Skip to content

Commit 10598bc

Browse files
committed
Updating tests to handle UUID type
Use UUID type for response identifier as well
1 parent 5c79d38 commit 10598bc

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ final class Test_TypeMatcher: Test_Core {
2828
(.string(contentEncoding: .base64), "OpenAPIRuntime.Base64EncodedData"),
2929
(.string(.init(format: .date), .init()), "Swift.String"),
3030
(.string(.init(format: .dateTime), .init()), "Foundation.Date"),
31+
(.string(.init(format: .uuid), .init()), "Foundation.UUID"),
3132

3233
(.integer, "Swift.Int"), (.integer(.init(format: .int32), .init()), "Swift.Int32"),
3334
(.integer(.init(format: .int64), .init()), "Swift.Int64"),

Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ paths:
7979
required: true
8080
schema:
8181
type: string
82+
format: uuid
8283
My-Tracing-Header:
8384
$ref: '#/components/headers/TracingHeader'
8485
content:

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
@preconcurrency import struct Foundation.URL
55
@preconcurrency import struct Foundation.Data
66
@preconcurrency import struct Foundation.Date
7+
@preconcurrency import struct Foundation.UUID
78
#else
89
import struct Foundation.URL
910
import struct Foundation.Data
1011
import struct Foundation.Date
12+
import struct Foundation.UUID
1113
#endif
1214
import HTTPTypes
1315
/// Service for managing pet metadata.
@@ -107,7 +109,7 @@ public struct Client: APIProtocol {
107109
My_hyphen_Response_hyphen_UUID: try converter.getRequiredHeaderFieldAsURI(
108110
in: response.headerFields,
109111
name: "My-Response-UUID",
110-
as: Swift.String.self
112+
as: Foundation.UUID.self
111113
),
112114
My_hyphen_Tracing_hyphen_Header: try converter.getOptionalHeaderFieldAsURI(
113115
in: response.headerFields,

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
@preconcurrency import struct Foundation.URL
55
@preconcurrency import struct Foundation.Data
66
@preconcurrency import struct Foundation.Date
7+
@preconcurrency import struct Foundation.UUID
78
#else
89
import struct Foundation.URL
910
import struct Foundation.Data
1011
import struct Foundation.Date
12+
import struct Foundation.UUID
1113
#endif
1214
import HTTPTypes
1315
extension APIProtocol {
@@ -199,7 +201,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
199201
My_hyphen_Request_hyphen_UUID: try converter.getOptionalHeaderFieldAsURI(
200202
in: request.headerFields,
201203
name: "My-Request-UUID",
202-
as: Swift.String.self
204+
as: Foundation.UUID.self
203205
),
204206
accept: try converter.extractAcceptHeaderIfPresent(in: request.headerFields)
205207
)

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
@preconcurrency import struct Foundation.URL
55
@preconcurrency import struct Foundation.Data
66
@preconcurrency import struct Foundation.Date
7+
@preconcurrency import struct Foundation.UUID
78
#else
89
import struct Foundation.URL
910
import struct Foundation.Data
1011
import struct Foundation.Date
12+
import struct Foundation.UUID
1113
#endif
1214
/// A type that performs HTTP operations defined by the OpenAPI document.
1315
public protocol APIProtocol: Sendable {
@@ -1820,15 +1822,15 @@ public enum Operations {
18201822
/// Request identifier
18211823
///
18221824
/// - Remark: Generated from `#/paths/pets/GET/header/My-Request-UUID`.
1823-
public var My_hyphen_Request_hyphen_UUID: Swift.String?
1825+
public var My_hyphen_Request_hyphen_UUID: Foundation.UUID?
18241826
public var accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.listPets.AcceptableContentType>]
18251827
/// Creates a new `Headers`.
18261828
///
18271829
/// - Parameters:
18281830
/// - My_hyphen_Request_hyphen_UUID: Request identifier
18291831
/// - accept:
18301832
public init(
1831-
My_hyphen_Request_hyphen_UUID: Swift.String? = nil,
1833+
My_hyphen_Request_hyphen_UUID: Foundation.UUID? = nil,
18321834
accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.listPets.AcceptableContentType>] = .defaultValues()
18331835
) {
18341836
self.My_hyphen_Request_hyphen_UUID = My_hyphen_Request_hyphen_UUID
@@ -1856,7 +1858,7 @@ public enum Operations {
18561858
/// Response identifier
18571859
///
18581860
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Response-UUID`.
1859-
public var My_hyphen_Response_hyphen_UUID: Swift.String
1861+
public var My_hyphen_Response_hyphen_UUID: Foundation.UUID
18601862
/// A description here.
18611863
///
18621864
/// - Remark: Generated from `#/paths/pets/GET/responses/200/headers/My-Tracing-Header`.
@@ -1867,7 +1869,7 @@ public enum Operations {
18671869
/// - My_hyphen_Response_hyphen_UUID: Response identifier
18681870
/// - My_hyphen_Tracing_hyphen_Header: A description here.
18691871
public init(
1870-
My_hyphen_Response_hyphen_UUID: Swift.String,
1872+
My_hyphen_Response_hyphen_UUID: Foundation.UUID,
18711873
My_hyphen_Tracing_hyphen_Header: Components.Headers.TracingHeader? = nil
18721874
) {
18731875
self.My_hyphen_Response_hyphen_UUID = My_hyphen_Response_hyphen_UUID

Tests/PetstoreConsumerTests/Common.swift

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
import XCTest
1515
import HTTPTypes
1616

17-
extension Operations.listPets.Output {
18-
static var success: Self { .ok(.init(headers: .init(My_hyphen_Response_hyphen_UUID: "abcd"), body: .json([]))) }
19-
}
20-
2117
extension HTTPRequest {
2218
/// Initializes an HTTP request with the specified path, HTTP method, and header fields.
2319
///

Tests/PetstoreConsumerTests/Test_Client.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ final class Test_Client: XCTestCase {
3636
}
3737

3838
func testListPets_200() async throws {
39+
let requestUUID = UUID()
40+
let responseUUID = UUID()
3941
transport = .init { (request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String) in
4042
XCTAssertEqual(operationID, "listPets")
4143
XCTAssertEqual(
@@ -44,12 +46,12 @@ final class Test_Client: XCTestCase {
4446
)
4547
XCTAssertEqual(baseURL.absoluteString, "/api")
4648
XCTAssertEqual(request.method, .get)
47-
XCTAssertEqual(request.headerFields, [.accept: "application/json", .init("My-Request-UUID")!: "abcd-1234"])
49+
XCTAssertEqual(request.headerFields, [.accept: "application/json", .init("My-Request-UUID")!: requestUUID.uuidString])
4850
XCTAssertNil(body)
4951
return try HTTPResponse(
5052
status: .ok,
5153
headerFields: [
52-
.contentType: "application/json", .init("my-response-uuid")!: "abcd",
54+
.contentType: "application/json", .init("my-response-uuid")!: responseUUID.uuidString,
5355
.init("my-tracing-header")!: "1234",
5456
]
5557
)
@@ -67,14 +69,14 @@ final class Test_Client: XCTestCase {
6769
let response = try await client.listPets(
6870
.init(
6971
query: .init(limit: 24, habitat: .water, feeds: [.herbivore, .carnivore], since: .test),
70-
headers: .init(My_hyphen_Request_hyphen_UUID: "abcd-1234")
72+
headers: .init(My_hyphen_Request_hyphen_UUID: requestUUID)
7173
)
7274
)
7375
guard case let .ok(value) = response else {
7476
XCTFail("Unexpected response: \(response)")
7577
return
7678
}
77-
XCTAssertEqual(value.headers.My_hyphen_Response_hyphen_UUID, "abcd")
79+
XCTAssertEqual(value.headers.My_hyphen_Response_hyphen_UUID, responseUUID)
7880
XCTAssertEqual(value.headers.My_hyphen_Tracing_hyphen_Header, "1234")
7981
switch value.body {
8082
case .json(let pets): XCTAssertEqual(pets, [.init(id: 1, name: "Fluffz")])

Tests/PetstoreConsumerTests/Test_Server.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ final class Test_Server: XCTestCase {
2828
}
2929

3030
func testListPets_200() async throws {
31+
let requestUUID = UUID()
32+
let responseUUID = UUID()
3133
client = .init(listPetsBlock: { input in
3234
XCTAssertEqual(input.query.limit, 24)
3335
XCTAssertEqual(input.query.habitat, .water)
3436
XCTAssertEqual(input.query.since, .test)
3537
XCTAssertEqual(input.query.feeds, [.carnivore, .herbivore])
36-
XCTAssertEqual(input.headers.My_hyphen_Request_hyphen_UUID, "abcd-1234")
38+
XCTAssertEqual(input.headers.My_hyphen_Request_hyphen_UUID, requestUUID)
3739
return .ok(
3840
.init(
39-
headers: .init(My_hyphen_Response_hyphen_UUID: "abcd", My_hyphen_Tracing_hyphen_Header: "1234"),
41+
headers: .init(My_hyphen_Response_hyphen_UUID: responseUUID, My_hyphen_Tracing_hyphen_Header: "1234"),
4042
body: .json([.init(id: 1, name: "Fluffz")])
4143
)
4244
)
@@ -45,7 +47,7 @@ final class Test_Server: XCTestCase {
4547
.init(
4648
soar_path: "/api/pets?limit=24&habitat=water&feeds=carnivore&feeds=herbivore&since=\(Date.testString)",
4749
method: .get,
48-
headerFields: [.init("My-Request-UUID")!: "abcd-1234"]
50+
headerFields: [.init("My-Request-UUID")!: requestUUID.uuidString]
4951
),
5052
nil,
5153
.init()
@@ -54,7 +56,7 @@ final class Test_Server: XCTestCase {
5456
XCTAssertEqual(
5557
response.headerFields,
5658
[
57-
.init("My-Response-UUID")!: "abcd", .init("My-Tracing-Header")!: "1234",
59+
.init("My-Response-UUID")!: responseUUID.uuidString, .init("My-Tracing-Header")!: "1234",
5860
.contentType: "application/json; charset=utf-8", .contentLength: "47",
5961
]
6062
)

0 commit comments

Comments
 (0)