Skip to content

Commit 9c0cf82

Browse files
committed
Add testTypeNameForReferenceProperties
1 parent c22e88d commit 9c0cf82

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ class Test_TypeAssigner: Test_Core {
104104
}
105105
}
106106

107+
func testTypeNameForReferenceProperties() throws {
108+
let parent = TypeName(swiftKeyPath: ["MyType"])
109+
let components: OpenAPI.Components = .init(schemas: [
110+
"SomeString": .string(),
111+
"MaybeString": .one(of: [.reference(.component(named: "SomeString")), .null()]),
112+
])
113+
func assertTypeName(_ property: String, _ schema: JSONSchema, _ typeName: String, file: StaticString = #file, line: UInt = #line) throws {
114+
let actual = try typeAssigner.typeUsage(
115+
forObjectPropertyNamed: property,
116+
withSchema: schema,
117+
components: components,
118+
inParent: parent
119+
).fullyQualifiedSwiftName
120+
XCTAssertEqual(typeName, actual, file: file, line: line)
121+
}
122+
try assertTypeName("someString", .reference(.component(named: "SomeString")), "Components.Schemas.SomeString")
123+
try assertTypeName("maybeString", .reference(.component(named: "MaybeString")), "Components.Schemas.MaybeString")
124+
try assertTypeName("optionalSomeString", .reference(.component(named: "SomeString"), required: false), "Components.Schemas.SomeString?")
125+
try assertTypeName("optionalMaybeString", .reference(.component(named: "MaybeString"), required: false), "Components.Schemas.MaybeString")
126+
}
127+
107128
func testContentSwiftName() throws {
108129
let nameMaker = makeTranslator().typeAssigner.contentSwiftName
109130
let cases: [(String, String)] = [

0 commit comments

Comments
 (0)