Skip to content

Commit 47a89bc

Browse files
committed
Soundness fixes
1 parent 78bd078 commit 47a89bc

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

Sources/OpenAPIRuntime/Conversion/Configuration.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public struct Configuration: Sendable {
166166
/// - jsonEncodingOptions: The options for the underlying JSON encoder.
167167
/// - multipartBoundaryGenerator: The generator to use when creating mutlipart bodies.
168168
/// - xmlCoder: Custom XML coder for encoding and decoding xml bodies. Only required when using XML body payloads.
169-
/// - errorMapper: An error mapping closure to allow customizing the final error thrown.
169+
/// - clientErrorMapper: An error mapping closure to allow customizing the error thrown by the client.
170+
/// - serverErrorMapper: An error mapping closure to allow customizing the error thrown by the server.
170171
public init(
171172
dateTranscoder: any DateTranscoder = .iso8601,
172173
jsonEncodingOptions: JSONEncodingOptions = [.sortedKeys, .prettyPrinted],

Sources/OpenAPIRuntime/Deprecated/Deprecated.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ extension Configuration {
6767
/// - jsonEncodingOptions: The options for the underlying JSON encoder.
6868
/// - multipartBoundaryGenerator: The generator to use when creating mutlipart bodies.
6969
/// - xmlCoder: Custom XML coder for encoding and decoding xml bodies. Only required when using XML body payloads.
70-
@available(*, deprecated, renamed: "init(dateTranscoder:jsonEncodingOptions:multipartBoundaryGenerator:xmlCoder:clientErrorMapper:serverErrorMapper:)")
71-
@_disfavoredOverload public init(
70+
@available(
71+
*,
72+
deprecated,
73+
renamed:
74+
"init(dateTranscoder:jsonEncodingOptions:multipartBoundaryGenerator:xmlCoder:clientErrorMapper:serverErrorMapper:)"
75+
) @_disfavoredOverload public init(
7276
dateTranscoder: any DateTranscoder = .iso8601,
7377
jsonEncodingOptions: JSONEncodingOptions = [.sortedKeys, .prettyPrinted],
7478
multipartBoundaryGenerator: any MultipartBoundaryGenerator = .random,

Sources/OpenAPIRuntime/Interface/UniversalServer.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ import struct Foundation.URLComponents
180180
}
181181
}
182182
}
183-
do {
184-
return try await next(request, requestBody, metadata)
185-
} catch {
183+
do { return try await next(request, requestBody, metadata) } catch {
186184
if let errorMapper, let serverError = error as? ServerError {
187185
throw errorMapper(serverError)
188186
} else {

Tests/OpenAPIRuntimeTests/Interface/Test_UniversalClient.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ final class Test_UniversalClient: Test_Runtime {
122122
func testErrorPropagation_customErrorMapper() async throws {
123123
do {
124124
let client = UniversalClient(
125-
configuration: .init(
126-
clientErrorMapper: { clientError in
127-
// Don't care about the extra context, just wants the underlyingError
128-
clientError.underlyingError
129-
}
130-
),
125+
configuration: .init(clientErrorMapper: { clientError in
126+
// Don't care about the extra context, just wants the underlyingError
127+
clientError.underlyingError
128+
}),
131129
transport: MockClientTransport.failing
132130
)
133131
try await client.send(
@@ -136,9 +134,7 @@ final class Test_UniversalClient: Test_Runtime {
136134
serializer: { input in (HTTPRequest(soar_path: "/", method: .post), MockClientTransport.requestBody) },
137135
deserializer: { response, body in fatalError() }
138136
)
139-
} catch {
140-
XCTAssertTrue(error is TestError, "Threw an unexpected error: \(type(of: error))")
141-
}
137+
} catch { XCTAssertTrue(error is TestError, "Threw an unexpected error: \(type(of: error))") }
142138
}
143139

144140
func testErrorPropagation_middlewareOnResponse() async throws {

Tests/OpenAPIRuntimeTests/Interface/Test_UniversalServer.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ final class Test_UniversalServer: Test_Runtime {
133133
do {
134134
let server = UniversalServer(
135135
handler: MockHandler(shouldFail: true),
136-
configuration: .init(
137-
serverErrorMapper: { serverError in
138-
// Don't care about the extra context, just wants the underlyingError
139-
serverError.underlyingError
140-
}
141-
)
136+
configuration: .init(serverErrorMapper: { serverError in
137+
// Don't care about the extra context, just wants the underlyingError
138+
serverError.underlyingError
139+
})
142140
)
143141
_ = try await server.handle(
144142
request: .init(soar_path: "/", method: .post),
@@ -152,9 +150,7 @@ final class Test_UniversalServer: Test_Runtime {
152150
},
153151
serializer: { output, _ in fatalError() }
154152
)
155-
} catch {
156-
XCTAssertTrue(error is TestError, "Threw an unexpected error: \(type(of: error))")
157-
}
153+
} catch { XCTAssertTrue(error is TestError, "Threw an unexpected error: \(type(of: error))") }
158154
}
159155

160156
func testErrorPropagation_serializer() async throws {

0 commit comments

Comments
 (0)