File tree 2 files changed +11
-7
lines changed
2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 8
8
import Foundation
9
9
import OpenAPIKit
10
10
11
- fileprivate let collidingNames = [
12
- " Metadata "
13
- ]
14
-
15
11
/// Given some JSON Schema, attempt to generate Swift code for
16
12
/// a `struct` that is capable of parsing data adhering to the schema.
17
13
public struct StructureSwiftGen : JSONSchemaSwiftGenerator {
@@ -36,7 +32,7 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
36
32
rootConformances: [ String ] ? = nil
37
33
) throws {
38
34
let typeName : String
39
- if collidingNames . contains ( swiftTypeName) {
35
+ if reservedTypeNames . contains ( swiftTypeName) {
40
36
typeName = " Gen " + swiftTypeName
41
37
} else {
42
38
typeName = swiftTypeName
@@ -49,15 +45,15 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
49
45
case . object( _, let context) :
50
46
decls = [
51
47
try StructureSwiftGen . structure (
52
- named: swiftTypeName ,
48
+ named: typeName ,
53
49
forObject: context,
54
50
cascadingConformances: cascadingConformances,
55
51
rootConformances: rootConformances
56
52
)
57
53
]
58
54
case . one( of: let schemas, core: _) :
59
55
let poly = try StructureSwiftGen . structure (
60
- named: swiftTypeName ,
56
+ named: typeName ,
61
57
forOneOf: schemas,
62
58
cascadingConformances: cascadingConformances,
63
59
rootConformances: rootConformances
Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ import Foundation
9
9
import OpenAPIKit
10
10
import JSONAPI
11
11
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
+
12
20
public protocol SwiftGenerator : SwiftCodeRepresentable {
13
21
var decls : [ Decl ] { get }
14
22
}
You can’t perform that action at this time.
0 commit comments