Vert.x

时间:2017-06-22 13:22:15

标签: swagger swagger-ui vert.x swagger-editor swagger-codegen

是否有适用于Vert.x的基于注释的Swagger文档创建器?其余的端点都是使用路由器管理的,因此如果有任何方法可以生成Swagger文档,那就太棒了。 我使用各种注释完成了基于Java Jersey的文档创建器,但找不到Vert.x文档的任何内容。 Git Hub上的官方招摇wiki也没有任何与Vert.x文档相关的文档。

1 个答案:

答案 0 :(得分:0)

自从提出此问题以来,Swagger被命名为OpenAPI,而Vert.x提供了Web API Contract模块。使用此anupsaund创建了vertx-auto-swagger回购(依次基于vertx-openapi-spec-generator)。它确实:

  
      
  • 阅读Java注释并将其映射到openAPI规范中。
  •   
  • 在端点上提供openAPI规范。
  •   
  • 提供SwaggerUI的可分发版本,该版本显示了第2点的swagger规范。
  •   

然后允许如下注释:

@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.")
    }
)
相关问题