这更像是一个库的原型,而不是一个完善或功能齐全的 API。即便如此,人们发现它很有用,如果您也觉得这个库有用,我当然鼓励您提交 PR 来修复和改进它!
自 OpenAPIKit v3.0.0 版本发布以来,此库生成与 OpenAPI v3.1 兼容的文档,而不是与 OpenAPI v3.0 兼容的文档。
请参阅 https://github.com/mattpolzin/VaporOpenAPIExample 以查看使用此库的简单应用程序示例。
您可以使用 VaporTypedRoutes.TypedRequest
而不是 Vapor.Request
来形成请求上下文,该上下文可用于构建 OpenAPI 描述。您可以使用自定义方法将路由附加到应用程序。这些方法镜像了 Vapor 中已有的方法。
您可以像这样将该库与 Swift 并发一起使用
enum WidgetController {
struct ShowRoute: RouteContext {
...
}
static func show(_ req: TypedRequest<ShowRoute>) try await -> Response {
...
}
}
func routes(_ app: Application) {
app.get(
"widgets",
":type".description("The type of widget"),
":id".parameterType(Int.self),
use: WidgetController.show
).tags("Widgets")
.summary("Get a widget")
}
...以及像这样与 NIO EventLoopFuture 一起使用
enum WidgetController {
struct ShowRoute: RouteContext {
...
}
static func show(_ req: TypedRequest<ShowRoute>) -> EventLoopFuture<Response> {
...
}
}
func routes(_ app: Application) {
app.get(
"widgets",
":type".description("The type of widget"),
":id".parameterType(Int.self),
use: WidgetController.show
).tags("Widgets")
.summary("Get a widget")
}