Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding midlewares #5

Open
sebsto opened this issue Dec 18, 2023 · 0 comments
Open

Consider adding midlewares #5

sebsto opened this issue Dec 18, 2023 · 0 comments

Comments

@sebsto
Copy link
Collaborator

sebsto commented Dec 18, 2023

Middleware : https://swiftpackageindex.com/apple/swift-openapi-runtime/1.0.0/documentation/openapiruntime/servermiddleware

Example : pass authentication information to the service

Possibly even for the already-authenticated requests, a middleware could extract the information about the user and put it into a task local value, making it easy to access from the generated handlers. This pattern is shown in this example.

Middleware extracts the info and puts it into a task local: https://github.com/apple/swift-openapi-generator/blob/main/Examples/auth-server-middleware-example/Sources/AuthenticationServerMiddleware/AuthenticationServerMiddleware.swift

The developer uses it in their generated handler: https://github.com/apple/swift-openapi-generator/blob/cd88cbe95c764553c0e7e04c2c1fb25d8ba5ae34/Examples/auth-server-middleware-example/Sources/HelloWorldVaporServer/HelloWorldVaporServer.swift#L26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant