Skip to content

Commit b6cf3d7

Browse files
committed
use the generated name in all the places.
1 parent ff89229 commit b6cf3d7

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Sources/JSONAPISwiftGen/Swift Generators/StructureSwiftGen.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
import Foundation
99
import OpenAPIKit
1010

11-
fileprivate let collidingNames = [
12-
"Metadata"
13-
]
14-
1511
/// Given some JSON Schema, attempt to generate Swift code for
1612
/// a `struct` that is capable of parsing data adhering to the schema.
1713
public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
@@ -36,7 +32,7 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
3632
rootConformances: [String]? = nil
3733
) throws {
3834
let typeName: String
39-
if collidingNames.contains(swiftTypeName) {
35+
if reservedTypeNames.contains(swiftTypeName) {
4036
typeName = "Gen" + swiftTypeName
4137
} else {
4238
typeName = swiftTypeName
@@ -49,15 +45,15 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
4945
case .object(_, let context):
5046
decls = [
5147
try StructureSwiftGen.structure(
52-
named: swiftTypeName,
48+
named: typeName,
5349
forObject: context,
5450
cascadingConformances: cascadingConformances,
5551
rootConformances: rootConformances
5652
)
5753
]
5854
case .one(of: let schemas, core: _):
5955
let poly = try StructureSwiftGen.structure(
60-
named: swiftTypeName,
56+
named: typeName,
6157
forOneOf: schemas,
6258
cascadingConformances: cascadingConformances,
6359
rootConformances: rootConformances

Sources/JSONAPISwiftGen/SwiftGen.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import Foundation
99
import OpenAPIKit
1010
import JSONAPI
1111

12+
/// A relatively ad-hoc list of names that if used for generated types in the
13+
/// wrong context could result in code ambiguity.
14+
internal let reservedTypeNames = [
15+
"Metadata",
16+
"Attributes",
17+
"Relationships"
18+
]
19+
1220
public protocol SwiftGenerator: SwiftCodeRepresentable {
1321
var decls: [Decl] { get }
1422
}

0 commit comments

Comments
 (0)