File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 88import Foundation
99import 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.
1713public 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
Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ import Foundation
99import OpenAPIKit
1010import 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+
1220public protocol SwiftGenerator : SwiftCodeRepresentable {
1321 var decls : [ Decl ] { get }
1422}
You can’t perform that action at this time.
0 commit comments