vapor/swift-openapi-vapor

Vapor Bindings for the OpenAPI Generator

112

stars

77

commits

Swift

primary language

Sep 2, 2026

updated

README

Swift OpenAPI Vapor

This package provides Vapor Bindings for the OpenAPI generator.

Usage

In entrypoint.swift add:

// Create a Vapor OpenAPI Transport using your application.
let transport = VaporTransport(routesBuilder: app)

// Create an instance of your handler type that conforms the generated protocol
// defining your service API.
let handler = MyServiceAPIImpl()

// Call the generated function on your implementation to add its request
// handlers to the app.
try handler.registerHandlers(on: transport)

Documentation

To get started, check out the full documentation, which contains step-by-step tutorials!

Additionally, see the request injection tutorial to learn how to inject Request into APIProtocol:

struct CurrentContext {
    @TaskLocal
    static var request: Request? = nil
}

struct MyAPIProtocolImpl: APIProtocol {
    func myOpenAPIEndpointFunction() async throws -> Operations.myOperation.Output {
        /// Use `request` as if this is a normal Vapor endpoint function
        CurrentContext.request?.logger.notice(
            "Got a request!",
            metadata: [
                "request": .stringConvertible(CurrentContext.request)
            ]
        )
    }
}

Contributors

0xTim

39 commits

MahdiBM

24 commits

tomerd

3 commits

gwynne

2 commits

vapor/swift-openapi-vapor

Vapor Bindings for the OpenAPI Generator

112

stars

77

commits

Swift

primary language

Sep 2, 2026

updated

README

Swift OpenAPI Vapor

This package provides Vapor Bindings for the OpenAPI generator.

Usage

In entrypoint.swift add:

// Create a Vapor OpenAPI Transport using your application.
let transport = VaporTransport(routesBuilder: app)

// Create an instance of your handler type that conforms the generated protocol
// defining your service API.
let handler = MyServiceAPIImpl()

// Call the generated function on your implementation to add its request
// handlers to the app.
try handler.registerHandlers(on: transport)

Documentation

To get started, check out the full documentation, which contains step-by-step tutorials!

Additionally, see the request injection tutorial to learn how to inject Request into APIProtocol:

struct CurrentContext {
    @TaskLocal
    static var request: Request? = nil
}

struct MyAPIProtocolImpl: APIProtocol {
    func myOpenAPIEndpointFunction() async throws -> Operations.myOperation.Output {
        /// Use `request` as if this is a normal Vapor endpoint function
        CurrentContext.request?.logger.notice(
            "Got a request!",
            metadata: [
                "request": .stringConvertible(CurrentContext.request)
            ]
        )
    }
}

Contributors

0xTim

39 commits

MahdiBM

24 commits

tomerd

3 commits

gwynne

2 commits

Languages

Swift

100.0%