Skip to content

Commit 4e5ff88

Browse files
committed
test fixes
1 parent 992b14b commit 4e5ff88

3 files changed

Lines changed: 62 additions & 52 deletions

File tree

Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ final class Test_validateDoc: Test_Core {
8181
.init(
8282
get: .init(
8383
requestBody: .b(
84-
.init(content: [.init(rawValue: "application/xml")!: .init(schema: .string)])
84+
.init(content: [.init(rawValue: "application/xml")!: .content(.init(schema: .string))])
8585
),
8686
responses: [
8787
.init(integerLiteral: 200): .b(
8888
.init(
8989
description: "Test description 1",
90-
content: [.init(rawValue: "application/json")!: .init(schema: .string)]
90+
content: [.init(rawValue: "application/json")!: .content(.init(schema: .string))]
9191
)
9292
)
9393
]
@@ -97,12 +97,12 @@ final class Test_validateDoc: Test_Core {
9797
"/path2": .b(
9898
.init(
9999
get: .init(
100-
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .init(schema: .string)])),
100+
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .content(.init(schema: .string))])),
101101
responses: [
102102
.init(integerLiteral: 200): .b(
103103
.init(
104104
description: "Test description 2",
105-
content: [.init(rawValue: "text/plain")!: .init(schema: .string)]
105+
content: [.init(rawValue: "text/plain")!: .content(.init(schema: .string))]
106106
)
107107
)
108108
]
@@ -127,12 +127,12 @@ final class Test_validateDoc: Test_Core {
127127
"/path1": .b(
128128
.init(
129129
get: .init(
130-
requestBody: .b(.init(content: [.init(rawValue: "application/")!: .init(schema: .string)])),
130+
requestBody: .b(.init(content: [.init(rawValue: "application/")!: .content(.init(schema: .string))])),
131131
responses: [
132132
.init(integerLiteral: 200): .b(
133133
.init(
134134
description: "Test description 1",
135-
content: [.init(rawValue: "application/json")!: .init(schema: .string)]
135+
content: [.init(rawValue: "application/json")!: .content(.init(schema: .string))]
136136
)
137137
)
138138
]
@@ -142,12 +142,12 @@ final class Test_validateDoc: Test_Core {
142142
"/path2": .b(
143143
.init(
144144
get: .init(
145-
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .init(schema: .string)])),
145+
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .content(.init(schema: .string))])),
146146
responses: [
147147
.init(integerLiteral: 200): .b(
148148
.init(
149149
description: "Test description 2",
150-
content: [.init(rawValue: "text/plain")!: .init(schema: .string)]
150+
content: [.init(rawValue: "text/plain")!: .content(.init(schema: .string))]
151151
)
152152
)
153153
]
@@ -179,13 +179,13 @@ final class Test_validateDoc: Test_Core {
179179
.init(
180180
get: .init(
181181
requestBody: .b(
182-
.init(content: [.init(rawValue: "application/xml")!: .init(schema: .string)])
182+
.init(content: [.init(rawValue: "application/xml")!: .content(.init(schema: .string))])
183183
),
184184
responses: [
185185
.init(integerLiteral: 200): .b(
186186
.init(
187187
description: "Test description 1",
188-
content: [.init(rawValue: "application/json")!: .init(schema: .string)]
188+
content: [.init(rawValue: "application/json")!: .content(.init(schema: .string))]
189189
)
190190
)
191191
]
@@ -195,12 +195,12 @@ final class Test_validateDoc: Test_Core {
195195
"/path2": .b(
196196
.init(
197197
get: .init(
198-
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .init(schema: .string)])),
198+
requestBody: .b(.init(content: [.init(rawValue: "text/html")!: .content(.init(schema: .string))])),
199199
responses: [
200200
.init(integerLiteral: 200): .b(
201201
.init(
202202
description: "Test description 2",
203-
content: [.init(rawValue: "/plain")!: .init(schema: .string)]
203+
content: [.init(rawValue: "/plain")!: .content(.init(schema: .string))]
204204
)
205205
)
206206
]
@@ -232,23 +232,23 @@ final class Test_validateDoc: Test_Core {
232232
.init(
233233
get: .init(
234234
requestBody: .b(
235-
.init(content: [.init(rawValue: "application/xml")!: .init(schema: .string)])
235+
.init(content: [.init(rawValue: "application/xml")!: .content(.init(schema: .string))])
236236
),
237237
responses: [
238238
.init(integerLiteral: 200): .b(
239239
.init(
240240
description: "Test description 1",
241-
content: [.init(rawValue: "application/json")!: .init(schema: .string)]
241+
content: [.init(rawValue: "application/json")!: .content(.init(schema: .string))]
242242
)
243243
)
244244
]
245245
)
246246
)
247247
)
248248
],
249-
components: .init(requestBodies: [
250-
"exampleRequestBody1": .init(content: [.init(rawValue: "application/pdf")!: .init(schema: .string)]),
251-
"exampleRequestBody2": .init(content: [.init(rawValue: "image/")!: .init(schema: .string)]),
249+
components: .direct(requestBodies: [
250+
"exampleRequestBody1": .init(content: [.init(rawValue: "application/pdf")!: .content(.init(schema: .string))]),
251+
"exampleRequestBody2": .init(content: [.init(rawValue: "image/")!: .content(.init(schema: .string))]),
252252
])
253253
)
254254
XCTAssertThrowsError(
@@ -273,28 +273,28 @@ final class Test_validateDoc: Test_Core {
273273
.init(
274274
get: .init(
275275
requestBody: .b(
276-
.init(content: [.init(rawValue: "application/xml")!: .init(schema: .string)])
276+
.init(content: [.init(rawValue: "application/xml")!: .content(.init(schema: .string))])
277277
),
278278
responses: [
279279
.init(integerLiteral: 200): .b(
280280
.init(
281281
description: "Test description 1",
282-
content: [.init(rawValue: "application/json")!: .init(schema: .string)]
282+
content: [.init(rawValue: "application/json")!: .content(.init(schema: .string))]
283283
)
284284
)
285285
]
286286
)
287287
)
288288
)
289289
],
290-
components: .init(responses: [
290+
components: .direct(responses: [
291291
"exampleRequestBody1": .init(
292292
description: "Test description 1",
293-
content: [.init(rawValue: "application/pdf")!: .init(schema: .string)]
293+
content: [.init(rawValue: "application/pdf")!: .content(.init(schema: .string))]
294294
),
295295
"exampleRequestBody2": .init(
296296
description: "Test description 2",
297-
content: [.init(rawValue: "")!: .init(schema: .string)]
297+
content: [.init(rawValue: "")!: .content(.init(schema: .string))]
298298
),
299299
])
300300
)
@@ -321,13 +321,12 @@ final class Test_validateDoc: Test_Core {
321321
get: .init(
322322
parameters: .init(
323323
arrayLiteral: .b(
324-
.init(
324+
.path(
325325
name: "ID",
326-
context: .path,
327326
content: [
328-
.init(rawValue: "text/plain")!: .init(
329-
schema: .a(.component(named: "Path1ParametersContentSchemaReference"))
330-
)
327+
.init(rawValue: "text/plain")!: .content(.init(
328+
schema: .reference(.component(named: "Path1ParametersContentSchemaReference"))
329+
))
331330
]
332331
)
333332
),
@@ -340,9 +339,9 @@ final class Test_validateDoc: Test_Core {
340339
.init(
341340
description: "ResponseDescription",
342341
content: [
343-
.init(rawValue: "text/plain")!: .init(
344-
schema: .a(.component(named: "ResponsesContentSchemaReference"))
345-
)
342+
.init(rawValue: "text/plain")!: .content(.init(
343+
schema: .reference(.component(named: "ResponsesContentSchemaReference"))
344+
))
346345
]
347346
)
348347
),
@@ -360,9 +359,9 @@ final class Test_validateDoc: Test_Core {
360359
parameters: .init(arrayLiteral: .a(.component(named: "Path3ExampleID"))),
361360
requestBody: .b(
362361
.init(content: [
363-
.init(rawValue: "text/html")!: .init(
364-
schema: .a(.component(named: "RequestBodyContentSchemaReference"))
365-
)
362+
.init(rawValue: "text/html")!: .content(.init(
363+
schema: .reference(.component(named: "RequestBodyContentSchemaReference"))
364+
))
366365
])
367366
),
368367
responses: [:],
@@ -371,16 +370,16 @@ final class Test_validateDoc: Test_Core {
371370
)
372371
),
373372
],
374-
components: .init(
373+
components: .direct(
375374
schemas: [
376375
"ResponsesContentSchemaReference": .init(schema: .string(.init(), .init())),
377376
"RequestBodyContentSchemaReference": .init(schema: .integer(.init(), .init())),
378377
"Path1ParametersContentSchemaReference": .init(schema: .string(.init(), .init())),
379378
],
380379
responses: ["ResponsesReference": .init(description: "Description")],
381380
parameters: [
382-
"Path3ExampleID": .init(name: "ID", context: .path, content: .init()),
383-
"Path1ParametersReference": .init(name: "Schema", context: .path, schema: .array),
381+
"Path3ExampleID": .path(name: "ID", content: .init()),
382+
"Path1ParametersReference": .path(name: "Schema", schema: .array),
384383
],
385384
requestBodies: [
386385
"RequestBodyReference": .init(content: .init())
@@ -404,9 +403,9 @@ final class Test_validateDoc: Test_Core {
404403
get: .init(
405404
requestBody: .b(
406405
.init(content: [
407-
.init(rawValue: "text/html")!: .init(
408-
schema: .a(.component(named: "RequestBodyContentSchemaReference"))
409-
)
406+
.init(rawValue: "text/html")!: .content(.init(
407+
schema: .reference(.component(named: "RequestBodyContentSchemaReference"))
408+
))
410409
])
411410
),
412411
responses: [:]

Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ final class Test_OperationDescription: Test_Core {
1919

2020
func testAllParameters_duplicates_retainOnlyOperationParameters() throws {
2121
let pathLevelParameter = UnresolvedParameter.b(
22-
OpenAPI.Parameter(name: "test", context: .query(required: false), schema: .integer)
22+
OpenAPI.Parameter.query(name: "test", required: false, schema: .integer)
2323
)
2424
let operationLevelParameter = UnresolvedParameter.b(
25-
OpenAPI.Parameter(name: "test", context: .query(required: false), schema: .string)
25+
OpenAPI.Parameter.query(name: "test", required: false, schema: .string)
2626
)
2727

2828
let pathItem = OpenAPI.PathItem(
@@ -37,10 +37,10 @@ final class Test_OperationDescription: Test_Core {
3737

3838
func testAllParameters_duplicates_keepsDuplicatesFromDifferentLocation() throws {
3939
let pathLevelParameter = UnresolvedParameter.b(
40-
OpenAPI.Parameter(name: "test", context: .query(required: false), schema: .integer)
40+
OpenAPI.Parameter.query(name: "test", required: false, schema: .integer)
4141
)
4242
let operationLevelParameter = UnresolvedParameter.b(
43-
OpenAPI.Parameter(name: "test", context: .path, schema: .string)
43+
OpenAPI.Parameter.path(name: "test", schema: .string)
4444
)
4545

4646
let pathItem = OpenAPI.PathItem(
@@ -55,13 +55,13 @@ final class Test_OperationDescription: Test_Core {
5555

5656
func testAllParameters_duplicates_ordering() throws {
5757
let pathLevelParameter = UnresolvedParameter.b(
58-
OpenAPI.Parameter(name: "test1", context: .query(required: false), schema: .integer)
58+
OpenAPI.Parameter.query(name: "test1", required: false, schema: .integer)
5959
)
6060
let duplicatedParameter = UnresolvedParameter.b(
61-
OpenAPI.Parameter(name: "test2", context: .query(required: false), schema: .integer)
61+
OpenAPI.Parameter.query(name: "test2", required: false, schema: .integer)
6262
)
6363
let operationLevelParameter = UnresolvedParameter.b(
64-
OpenAPI.Parameter(name: "test3", context: .query(required: false), schema: .string)
64+
OpenAPI.Parameter.query(name: "test3", required: false, schema: .string)
6565
)
6666

6767
let pathItem = OpenAPI.PathItem(

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6321,7 +6321,9 @@ extension SnippetBasedReferenceTests {
63216321
line: UInt = #line
63226322
) throws {
63236323
let translator = try makeTypesTranslator(componentsYAML: componentsYAML)
6324-
let translation = try translator.translateComponentHeaders(translator.components.headers)
6324+
let components = translator.components
6325+
let componentHeaders = try components.headers.mapValues { try components.assumeLookupOnce($0) }
6326+
let translation = try translator.translateComponentHeaders(componentHeaders)
63256327
try XCTAssertSwiftEquivalent(translation, expectedSwift, file: file, line: line)
63266328
}
63276329

@@ -6333,7 +6335,9 @@ extension SnippetBasedReferenceTests {
63336335
line: UInt = #line
63346336
) throws {
63356337
let translator = try makeTypesTranslator(accessModifier: accessModifier, componentsYAML: componentsYAML)
6336-
let translation = try translator.translateComponentParameters(translator.components.parameters)
6338+
let components = translator.components
6339+
let componentParameters = try components.parameters.mapValues { try components.assumeLookupOnce($0) }
6340+
let translation = try translator.translateComponentParameters(componentParameters)
63376341
try XCTAssertSwiftEquivalent(translation, expectedSwift, file: file, line: line)
63386342
}
63396343

@@ -6379,8 +6383,9 @@ extension SnippetBasedReferenceTests {
63796383
try XCTAssertSwiftEquivalent(generatedSchemasStructuredSwift, expectedSchemasSwift, file: file, line: line)
63806384
}
63816385
if let expectedRequestBodiesSwift {
6386+
let componentRequestBodies = try components.requestBodies.mapValues { try components.assumeLookupOnce($0) }
63826387
let generatedRequestBodiesStructuredSwift = try types.translateComponentRequestBodies(
6383-
document.components.requestBodies
6388+
componentRequestBodies
63846389
)
63856390
try XCTAssertSwiftEquivalent(
63866391
generatedRequestBodiesStructuredSwift,
@@ -6438,8 +6443,10 @@ extension SnippetBasedReferenceTests {
64386443
try XCTAssertSwiftEquivalent(generatedSchemasStructuredSwift, expectedSchemasSwift, file: file, line: line)
64396444
}
64406445
if let expectedResponsesSwift {
6446+
let components = document.components
6447+
let componentResponses = try components.responses.mapValues { try components.assumeLookupOnce($0) }
64416448
let generatedRequestBodiesStructuredSwift = try types.translateComponentResponses(
6442-
document.components.responses
6449+
componentResponses
64436450
)
64446451
try XCTAssertSwiftEquivalent(
64456452
generatedRequestBodiesStructuredSwift,
@@ -6496,7 +6503,9 @@ extension SnippetBasedReferenceTests {
64966503
ignoredDiagnosticMessages: ignoredDiagnosticMessages,
64976504
componentsYAML: componentsYAML
64986505
)
6499-
let translation = try translator.translateComponentResponses(translator.components.responses)
6506+
let components = translator.components
6507+
let componentResponses = try components.responses.mapValues { try components.assumeLookupOnce($0) }
6508+
let translation = try translator.translateComponentResponses(componentResponses)
65006509
try XCTAssertSwiftEquivalent(translation, expectedSwift, file: file, line: line)
65016510
}
65026511

@@ -6513,7 +6522,9 @@ extension SnippetBasedReferenceTests {
65136522
ignoredDiagnosticMessages: ignoredDiagnosticMessages,
65146523
componentsYAML: componentsYAML
65156524
)
6516-
let translation = try translator.translateComponentRequestBodies(translator.components.requestBodies)
6525+
let components = translator.components
6526+
let componentRequestBodies = try components.requestBodies.mapValues { try components.assumeLookupOnce($0) }
6527+
let translation = try translator.translateComponentRequestBodies(componentRequestBodies)
65176528
try XCTAssertSwiftEquivalent(translation, expectedSwift, file: file, line: line)
65186529
}
65196530

0 commit comments

Comments
 (0)