5

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?

krishna
  • 1,029
  • 6
  • 12
Eko Susilo
  • 137
  • 2
  • 9
  • i think you should use io.swagger.core.v3 as these annotations are related to OpenAPI v3 spec (Swagger 2 is aka OpenAPI v2). – Simon Logic Feb 16 '21 at 14:04

0 Answers0