Vert.x 基于注解的 Swagger 文档

Annotation-based Swagger documentation for Vert.x

是否有可用于 Vert.x 的基于注释的 Swagger 文档创建器?其余端点均使用路由器进行管理,因此,如果有任何方法可用于生成 Swagger 文档,那就太好了。 我已经使用各种注释浏览了基于 Java Jersey 的文档创建器,但找不到 Vert.x 文档的任何内容。 Git Hub 上的官方 swagger wiki 也没有包含任何与 Vert.x 文档相关的文档。

自从有人问这个问题后,Swagger 被命名为 OpenAPI 并且 Vert.x 提供了 Web API Contract module. Using this anupsaund created the vertx-auto-swagger repo (in turn based on vertx-openapi-spec-generator)。它确实:

  • Read Java Annotations and map them into a openAPI spec.
  • Serve the openAPI spec out on an end point.
  • Serve a distributable version of SwaggerUI which presents the swagger spec from point 2.

然后允许注释如下:

@Operation(summary = "Find products by ID", method = "GET", operationId = "product/:productId",
    tags = {
        "Product"
    },
    parameters = {
        @Parameter(in = ParameterIn.PATH, name = "productId",
                required = true, description = "The unique ID belonging to the product", schema = @Schema(type = "string"))
    },
    responses = {
        @ApiResponse(responseCode = "200", description = "OK",
            content = @Content(
                mediaType = "application/json",
                encoding = @Encoding(contentType = "application/json"),
                schema = @Schema(name = "product", example =
                    "{" +
                            "'_id':'abc'," +
                            "'title':'Red Truck'," +
                            "'image_url':'https://images.pexels.com/photos/1112597/pexels-photo-1112597.jpeg'," +
                            "'from_date':'2018-08-30'," +
                            "'to_date':'2019-08-30'," +
                            "'price':'125.00'," +
                            "'enabled':true" +
                            "}",
                    implementation = Product.class)
            )
        ),
        @ApiResponse(responseCode = "404", description = "Not found."),
        @ApiResponse(responseCode = "500", description = "Internal Server Error.")
    }
)