This package provides Vapor Bindings for the OpenAPI generator.
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)
To get started, check out the full documentation, which contains step-by-step tutorials!
Additionally, see the request injection tutorial to learn how you can use swift-dependencies to inject Request
into APIProtocol
:
struct MyAPIProtocolImpl: APIProtocol {
@Dependency(\.request) var request
func myOpenAPIEndpointFunction() async throws -> Operations.myOperation.Output {
/// Use `request` as if this is a normal Vapor endpoint function
request.logger.notice(
"Got a request!",
metadata: [
"request": .stringConvertible(request)
]
)
}
}