Skip to content

Commit

Permalink
Fix server handler Sendability warnings (#156)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
czechboy0 authored Jul 31, 2023
1 parent 249ce5b commit 90c249e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,17 @@ extension ServerFileTranslator {
)
let methodArg: FunctionArgumentDescription = .init(
label: "using",
expression: .identifier(Constants.Server.Universal.apiHandlerName)
.dot(description.methodName)
expression: .closureInvocation(
body: [
.expression(
.identifier(Constants.Server.Universal.apiHandlerName)
.dot(description.methodName)
.call([
.init(label: nil, expression: .identifier("$0"))
])
)
]
)
)
let deserializerArg: FunctionArgumentDescription = .init(
label: "deserializer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
request: request,
with: metadata,
forOperation: Operations.listPets.id,
using: APIHandler.listPets,
using: { APIHandler.listPets($0) },
deserializer: { request, metadata in let path: Operations.listPets.Input.Path = .init()
let query: Operations.listPets.Input.Query = .init(
limit: try converter.getOptionalQueryItemAsText(
Expand Down Expand Up @@ -179,7 +179,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
request: request,
with: metadata,
forOperation: Operations.createPet.id,
using: APIHandler.createPet,
using: { APIHandler.createPet($0) },
deserializer: { request, metadata in
try converter.validateContentTypeIfPresent(
in: request.headerFields,
Expand Down Expand Up @@ -279,7 +279,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
request: request,
with: metadata,
forOperation: Operations.probe.id,
using: APIHandler.probe,
using: { APIHandler.probe($0) },
deserializer: { request, metadata in let path: Operations.probe.Input.Path = .init()
let query: Operations.probe.Input.Query = .init()
let headers: Operations.probe.Input.Headers = .init()
Expand Down Expand Up @@ -314,7 +314,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
request: request,
with: metadata,
forOperation: Operations.updatePet.id,
using: APIHandler.updatePet,
using: { APIHandler.updatePet($0) },
deserializer: { request, metadata in
try converter.validateContentTypeIfPresent(
in: request.headerFields,
Expand Down Expand Up @@ -389,7 +389,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
request: request,
with: metadata,
forOperation: Operations.uploadAvatarForPet.id,
using: APIHandler.uploadAvatarForPet,
using: { APIHandler.uploadAvatarForPet($0) },
deserializer: { request, metadata in
try converter.validateContentTypeIfPresent(
in: request.headerFields,
Expand Down

0 comments on commit 90c249e

Please sign in to comment.