此包为 OpenAPI 生成器 提供 Vapor 绑定。
在 entrypoint.swift
中添加
// 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)
要开始使用,请查看完整的文档,其中包含逐步教程!
此外,请参阅请求注入教程,了解如何使用 swift-dependencies 将 Request
注入到 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)
]
)
}
}