目录
目录README.md

VaporOpenAPI

This is currently in early stages of development, not a polished or feature-complete API by a long stretch.

See https://github.com/mattpolzin/VaporOpenAPIExample for an example of a simple app using this library.

You use VaporTypedRoutes.TypedRequest instead of Vapor.Request to form a request context that can be used to build out an OpenAPI description. You use custom methods to attach your routes to the app. These methods mirror the methods available in Vapor already.

You can use the library like this with Swift Concurrency:

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")
}

…and like this with a 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")
}
关于
114.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号