Skip to content

Consider adding midlewares  #5

Description

@sebsto

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions