Skip to content

Commit ff89229

Browse files
committed
try a different approach to renaming Metadata
1 parent 52542c3 commit ff89229

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/JSONAPISwiftGen/Swift Generators/StructureSwiftGen.swift

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

11+
fileprivate let collidingNames = [
12+
"Metadata"
13+
]
14+
1115
/// Given some JSON Schema, attempt to generate Swift code for
1216
/// a `struct` that is capable of parsing data adhering to the schema.
1317
public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
@@ -31,7 +35,14 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
3135
cascadingConformances: [String] = [],
3236
rootConformances: [String]? = nil
3337
) throws {
34-
self.swiftTypeName = swiftTypeName
38+
let typeName: String
39+
if collidingNames.contains(swiftTypeName) {
40+
typeName = "Gen" + swiftTypeName
41+
} else {
42+
typeName = swiftTypeName
43+
}
44+
45+
self.swiftTypeName = typeName
3546
self.structure = structure
3647

3748
switch structure {
@@ -102,7 +113,7 @@ public struct StructureSwiftGen: JSONSchemaSwiftGenerator {
102113
}
103114

104115
let poly = Typealias(
105-
alias: .def(.init(name: "Poly\(name)")),
116+
alias: .def(.init(name: name)),
106117
existingType: .def(
107118
.init(
108119
name: "Poly\(dependencies.count)",

0 commit comments

Comments
 (0)