Skip to content

Commit 90c249e

Browse files
authored
Fix server handler Sendability warnings (#156)
Fix server handler Sendability warnings ### Motivation Fixes a warning emitted for each operation method in generated server code, which looked like: ``` Converting non-sendable function value to '@sendable (APIHandler) -> ((Operations.listPets.Input) async throws -> Operations.listPets.Output)' may introduce data races ``` ### Modifications Instead of passing the function itself, we now invoke it in a closure. ### Result The warning has gone away. ### Test Plan Adapted integration tests. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #156
1 parent 249ce5b commit 90c249e

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,17 @@ extension ServerFileTranslator {
206206
)
207207
let methodArg: FunctionArgumentDescription = .init(
208208
label: "using",
209-
expression: .identifier(Constants.Server.Universal.apiHandlerName)
210-
.dot(description.methodName)
209+
expression: .closureInvocation(
210+
body: [
211+
.expression(
212+
.identifier(Constants.Server.Universal.apiHandlerName)
213+
.dot(description.methodName)
214+
.call([
215+
.init(label: nil, expression: .identifier("$0"))
216+
])
217+
)
218+
]
219+
)
211220
)
212221
let deserializerArg: FunctionArgumentDescription = .init(
213222
label: "deserializer",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
6969
request: request,
7070
with: metadata,
7171
forOperation: Operations.listPets.id,
72-
using: APIHandler.listPets,
72+
using: { APIHandler.listPets($0) },
7373
deserializer: { request, metadata in let path: Operations.listPets.Input.Path = .init()
7474
let query: Operations.listPets.Input.Query = .init(
7575
limit: try converter.getOptionalQueryItemAsText(
@@ -179,7 +179,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
179179
request: request,
180180
with: metadata,
181181
forOperation: Operations.createPet.id,
182-
using: APIHandler.createPet,
182+
using: { APIHandler.createPet($0) },
183183
deserializer: { request, metadata in
184184
try converter.validateContentTypeIfPresent(
185185
in: request.headerFields,
@@ -279,7 +279,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
279279
request: request,
280280
with: metadata,
281281
forOperation: Operations.probe.id,
282-
using: APIHandler.probe,
282+
using: { APIHandler.probe($0) },
283283
deserializer: { request, metadata in let path: Operations.probe.Input.Path = .init()
284284
let query: Operations.probe.Input.Query = .init()
285285
let headers: Operations.probe.Input.Headers = .init()
@@ -314,7 +314,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
314314
request: request,
315315
with: metadata,
316316
forOperation: Operations.updatePet.id,
317-
using: APIHandler.updatePet,
317+
using: { APIHandler.updatePet($0) },
318318
deserializer: { request, metadata in
319319
try converter.validateContentTypeIfPresent(
320320
in: request.headerFields,
@@ -389,7 +389,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
389389
request: request,
390390
with: metadata,
391391
forOperation: Operations.uploadAvatarForPet.id,
392-
using: APIHandler.uploadAvatarForPet,
392+
using: { APIHandler.uploadAvatarForPet($0) },
393393
deserializer: { request, metadata in
394394
try converter.validateContentTypeIfPresent(
395395
in: request.headerFields,

0 commit comments

Comments
 (0)