Skip to content

Commit

Permalink
Use UUID type for response identifier as well
Browse files Browse the repository at this point in the history
  • Loading branch information
gentges committed Sep 17, 2024
1 parent 67d72ec commit b4a1a4b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ paths:
required: true
schema:
type: string
format: uuid
My-Tracing-Header:
$ref: '#/components/headers/TracingHeader'
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public struct Client: APIProtocol {
My_hyphen_Response_hyphen_UUID: try converter.getRequiredHeaderFieldAsURI(
in: response.headerFields,
name: "My-Response-UUID",
as: Swift.String.self
as: Foundation.UUID.self
),
My_hyphen_Tracing_hyphen_Header: try converter.getOptionalHeaderFieldAsURI(
in: response.headerFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ public enum Operations {
/// Response identifier
///
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Response-UUID`.
public var My_hyphen_Response_hyphen_UUID: Swift.String
public var My_hyphen_Response_hyphen_UUID: Foundation.UUID
/// A description here.
///
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Tracing-Header`.
Expand All @@ -1869,7 +1869,7 @@ public enum Operations {
/// - My_hyphen_Response_hyphen_UUID: Response identifier
/// - My_hyphen_Tracing_hyphen_Header: A description here.
public init(
My_hyphen_Response_hyphen_UUID: Swift.String,
My_hyphen_Response_hyphen_UUID: Foundation.UUID,
My_hyphen_Tracing_hyphen_Header: Components.Headers.TracingHeader? = nil
) {
self.My_hyphen_Response_hyphen_UUID = My_hyphen_Response_hyphen_UUID
Expand Down
4 changes: 0 additions & 4 deletions Tests/PetstoreConsumerTests/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
import XCTest
import HTTPTypes

extension Operations.listPets.Output {
static var success: Self { .ok(.init(headers: .init(My_hyphen_Response_hyphen_UUID: "abcd"), body: .json([]))) }
}

extension HTTPRequest {
/// Initializes an HTTP request with the specified path, HTTP method, and header fields.
///
Expand Down
5 changes: 3 additions & 2 deletions Tests/PetstoreConsumerTests/Test_Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class Test_Client: XCTestCase {

func testListPets_200() async throws {
let requestUUID = UUID()
let responseUUID = UUID()
transport = .init { (request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String) in
XCTAssertEqual(operationID, "listPets")
XCTAssertEqual(
Expand All @@ -50,7 +51,7 @@ final class Test_Client: XCTestCase {
return try HTTPResponse(
status: .ok,
headerFields: [
.contentType: "application/json", .init("my-response-uuid")!: "abcd",
.contentType: "application/json", .init("my-response-uuid")!: responseUUID.uuidString,
.init("my-tracing-header")!: "1234",
]
)
Expand All @@ -75,7 +76,7 @@ final class Test_Client: XCTestCase {
XCTFail("Unexpected response: \(response)")
return
}
XCTAssertEqual(value.headers.My_hyphen_Response_hyphen_UUID, "abcd")
XCTAssertEqual(value.headers.My_hyphen_Response_hyphen_UUID, responseUUID)
XCTAssertEqual(value.headers.My_hyphen_Tracing_hyphen_Header, "1234")
switch value.body {
case .json(let pets): XCTAssertEqual(pets, [.init(id: 1, name: "Fluffz")])
Expand Down
5 changes: 3 additions & 2 deletions Tests/PetstoreConsumerTests/Test_Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class Test_Server: XCTestCase {

func testListPets_200() async throws {
let requestUUID = UUID()
let responseUUID = UUID()
client = .init(listPetsBlock: { input in
XCTAssertEqual(input.query.limit, 24)
XCTAssertEqual(input.query.habitat, .water)
Expand All @@ -37,7 +38,7 @@ final class Test_Server: XCTestCase {
XCTAssertEqual(input.headers.My_hyphen_Request_hyphen_UUID, requestUUID)
return .ok(
.init(
headers: .init(My_hyphen_Response_hyphen_UUID: "abcd", My_hyphen_Tracing_hyphen_Header: "1234"),
headers: .init(My_hyphen_Response_hyphen_UUID: responseUUID, My_hyphen_Tracing_hyphen_Header: "1234"),
body: .json([.init(id: 1, name: "Fluffz")])
)
)
Expand All @@ -55,7 +56,7 @@ final class Test_Server: XCTestCase {
XCTAssertEqual(
response.headerFields,
[
.init("My-Response-UUID")!: "abcd", .init("My-Tracing-Header")!: "1234",
.init("My-Response-UUID")!: responseUUID.uuidString, .init("My-Tracing-Header")!: "1234",
.contentType: "application/json; charset=utf-8", .contentLength: "47",
]
)
Expand Down

0 comments on commit b4a1a4b

Please sign in to comment.