Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation-based Swagger documentation for Vert.x

Is there any annotation based Swagger Documentation creator available for Vert.x yet ? The rest end points are all managed using routers and as such if there is any way available to generate the Swagger documentation, that would be great. I've gone through the Java Jersey based documentation creator using various annotations, but couldn't find anything for the Vert.x documentation. The official swagger wiki on Git Hub also doesn't house any document related to Vert.x documentations.

like image 358
DebashisDeb Avatar asked Jun 22 '17 13:06

DebashisDeb


People also ask

What are Swagger annotations used for?

The @ApiModelProperty annotation allows us to control Swagger-specific definitions such as description (value), name, data type, example values, and allowed values for the model properties. Also, it offers additional filtering properties in case we want to hide the property in certain scenarios.

What is @schema annotation in Swagger?

The annotation may be used to define a Schema for a set of elements of the OpenAPI spec, and/or to define additional properties for the schema. It is applicable e.g. to parameters, schema classes (aka "models"), properties of such models, request and response content, header.

What is @API annotation in Swagger?

The Springfox library provides @Api annotation to configure a class as a Swagger resource. Previously, the @Api annotation provided a description attribute to customize the API documentation: @Api(value = "", description = "") However, as mentioned earlier, the description attribute is deprecated.


1 Answers

Since this question was asked Swagger has been named OpenAPI and Vert.x offers the Web API Contract module. Using this anupsaund created the vertx-auto-swagger repo (in turn based on vertx-openapi-spec-generator). It does:

  • 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.

Which then allows annotations as follows:

@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.")
    }
)
like image 120
Arnold Schrijver Avatar answered Sep 21 '22 02:09

Arnold Schrijver