Skip to content

Commit ab6dd25

Browse files
committed
update runtime to 0.3.2, add client,server base64 tests
1 parent c4d704a commit ab6dd25

File tree

5 files changed

+163
-2
lines changed

5 files changed

+163
-2
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let package = Package(
8989
// Tests-only: Runtime library linked by generated code, and also
9090
// helps keep the runtime library new enough to work with the generated
9191
// code.
92-
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.1")),
92+
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.2")),
9393

9494
// Build and preview docs
9595
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),

Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ components:
311311
$ref: '#/components/schemas/PetKind'
312312
tag:
313313
type: string
314+
genome:
315+
type: string
316+
format: byte
314317
Pets:
315318
type: array
316319
items:

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,31 @@ public enum Components {
290290
public var kind: Components.Schemas.PetKind?
291291
/// - Remark: Generated from `#/components/schemas/CreatePetRequest/tag`.
292292
public var tag: Swift.String?
293+
/// - Remark: Generated from `#/components/schemas/CreatePetRequest/genome`.
294+
public var genome: OpenAPIRuntime.Base64EncodedData?
293295
/// Creates a new `CreatePetRequest`.
294296
///
295297
/// - Parameters:
296298
/// - name:
297299
/// - kind:
298300
/// - tag:
299-
public init(name: Swift.String, kind: Components.Schemas.PetKind? = nil, tag: Swift.String? = nil) {
301+
/// - genome:
302+
public init(
303+
name: Swift.String,
304+
kind: Components.Schemas.PetKind? = nil,
305+
tag: Swift.String? = nil,
306+
genome: OpenAPIRuntime.Base64EncodedData? = nil
307+
) {
300308
self.name = name
301309
self.kind = kind
302310
self.tag = tag
311+
self.genome = genome
303312
}
304313
public enum CodingKeys: String, CodingKey {
305314
case name
306315
case kind
307316
case tag
317+
case genome
308318
}
309319
}
310320
/// - Remark: Generated from `#/components/schemas/Pets`.

Tests/PetstoreConsumerTests/Test_Client.swift

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,87 @@ final class Test_Client: XCTestCase {
357357
}
358358
}
359359

360+
func testCreatePet_201_withBase64() async throws {
361+
transport = .init { request, body, baseURL, operationID in
362+
XCTAssertEqual(operationID, "createPet")
363+
XCTAssertEqual(request.path, "/pets")
364+
XCTAssertEqual(baseURL.absoluteString, "/api")
365+
XCTAssertEqual(request.method, .post)
366+
XCTAssertEqual(
367+
request.headerFields,
368+
[
369+
.accept: "application/json",
370+
.contentType: "application/json; charset=utf-8",
371+
.init("X-Extra-Arguments")!: #"{"code":1}"#,
372+
]
373+
)
374+
let bodyString: String
375+
if let body {
376+
bodyString = try await String(collecting: body, upTo: .max)
377+
} else {
378+
bodyString = ""
379+
}
380+
XCTAssertEqual(
381+
bodyString,
382+
#"""
383+
{
384+
"genome" : "IkdBQ1RBVFRDQVRBR0FHVFRUQ0FDQ1RDQUdHQUdBR0FHQUFHVEFBR0NBVFRBR0NBR0NUR0Mi",
385+
"name" : "Fluffz"
386+
}
387+
"""#
388+
)
389+
return try HTTPResponse(
390+
status: .created,
391+
headerFields: [
392+
.contentType: "application/json; charset=utf-8",
393+
.init("x-extra-arguments")!: #"{"code":1}"#,
394+
]
395+
)
396+
.withEncodedBody(
397+
#"""
398+
{
399+
"id": 1,
400+
"genome" : "IkdBQ1RBVFRDQVRBR0FHVFRUQ0FDQ1RDQUdHQUdBR0FHQUFHVEFBR0NBVFRBR0NBR0NUR0Mi",
401+
"name": "Fluffz"
402+
}
403+
"""#
404+
)
405+
}
406+
let response = try await client.createPet(
407+
.init(
408+
headers: .init(
409+
X_hyphen_Extra_hyphen_Arguments: .init(code: 1)
410+
),
411+
body: .json(
412+
.init(
413+
name: "Fluffz",
414+
genome: Base64EncodedData(
415+
data: ArraySlice(#""GACTATTCATAGAGTTTCACCTCAGGAGAGAGAAGTAAGCATTAGCAGCTGC""#.utf8)
416+
)
417+
)
418+
)
419+
)
420+
)
421+
guard case let .created(value) = response else {
422+
XCTFail("Unexpected response: \(response)")
423+
return
424+
}
425+
XCTAssertEqual(value.headers.X_hyphen_Extra_hyphen_Arguments, .init(code: 1))
426+
switch value.body {
427+
case .json(let pets):
428+
XCTAssertEqual(
429+
pets,
430+
.init(
431+
id: 1,
432+
name: "Fluffz",
433+
genome: Base64EncodedData(
434+
data: ArraySlice(#""GACTATTCATAGAGTTTCACCTCAGGAGAGAGAAGTAAGCATTAGCAGCTGC""#.utf8)
435+
)
436+
)
437+
)
438+
}
439+
}
440+
360441
func testUpdatePet_400() async throws {
361442
transport = .init { request, requestBody, baseURL, operationID in
362443
XCTAssertEqual(operationID, "updatePet")

Tests/PetstoreConsumerTests/Test_Server.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,73 @@ final class Test_Server: XCTestCase {
293293
)
294294
}
295295

296+
func testCreatePet_201_withBase64() async throws {
297+
client = .init(
298+
createPetBlock: { input in
299+
XCTAssertEqual(input.headers.X_hyphen_Extra_hyphen_Arguments, .init(code: 1))
300+
guard case let .json(createPet) = input.body else {
301+
throw TestError.unexpectedValue(input.body)
302+
}
303+
XCTAssertEqual(
304+
createPet,
305+
.init(
306+
name: "Fluffz",
307+
genome: Base64EncodedData(
308+
data: ArraySlice(#""GACTATTCATAGAGTTTCACCTCAGGAGAGAGAAGTAAGCATTAGCAGCTGC""#.utf8)
309+
)
310+
)
311+
)
312+
return .created(
313+
.init(
314+
headers: .init(
315+
X_hyphen_Extra_hyphen_Arguments: .init(code: 1)
316+
),
317+
body: .json(
318+
.init(id: 1, name: "Fluffz")
319+
)
320+
)
321+
)
322+
}
323+
)
324+
let (response, responseBody) = try await server.createPet(
325+
.init(
326+
soar_path: "/api/pets",
327+
method: .post,
328+
headerFields: [
329+
.init("x-extra-arguments")!: #"{"code":1}"#,
330+
.contentType: "application/json; charset=utf-8",
331+
]
332+
),
333+
.init(
334+
#"""
335+
{
336+
337+
"genome" : "IkdBQ1RBVFRDQVRBR0FHVFRUQ0FDQ1RDQUdHQUdBR0FHQUFHVEFBR0NBVFRBR0NBR0NUR0Mi",
338+
"name" : "Fluffz"
339+
}
340+
"""#
341+
),
342+
.init()
343+
)
344+
XCTAssertEqual(response.status.code, 201)
345+
XCTAssertEqual(
346+
response.headerFields,
347+
[
348+
.init("X-Extra-Arguments")!: #"{"code":1}"#,
349+
.contentType: "application/json; charset=utf-8",
350+
]
351+
)
352+
try await XCTAssertEqualStringifiedData(
353+
responseBody,
354+
#"""
355+
{
356+
"id" : 1,
357+
"name" : "Fluffz"
358+
}
359+
"""#
360+
)
361+
}
362+
296363
func testUpdatePet_204_withBody() async throws {
297364
client = .init(
298365
updatePetBlock: { input in

0 commit comments

Comments
 (0)