swagger ApiResponse example

Viewed 6319

I am trying to document an api error response with a example of the json body. I couldn't find an example or a fitting annotation. Playing around with the swagger editor I could at least get something that looks like the result I want to achieve.

responses:
    '200' :
      description: Request completed with no errors
      examples:   
        application/json:  {"result" : { "id": "blue" }}

libraries being is swagger-core 1.6.0

 <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-core</artifactId>
            <scope>compile</scope>
            <version>1.6.0</version>
</dependency>

and the endpoints are created using jax-rs.

I did this to the endpoint

@ApiResponses(value = {
    @ApiResponse(code = 200, message = "OK",
            examples = @Example(value = @ExampleProperty(mediaType = "application/json", value = "{\"result\" : { \"id\": \"blue\" }}"))
    )
})
public Response getResult(){}   


The generated swagger.json doesn't have the desired

examples:   
 application/json:  {"result" : { "id": "blue" }}         

I tried also passing response = ApiResponse.class, Examples.class and Example.class but it doesn't change.

How can I do this with annotations?

0 Answers
Related