Prevent ResponseEntity being generated as OpenAPI model

Posted on by  
Tom de Vroomen

When using Springfox you can annotate your endpoints to automatically generate OpenAPI docs for your clients.
This blogpost will show how you can prevent Springfox generating a model on an endpoint with ResponseEntity as return type.
I’ll also cover how to prevent generating default responses.

Take an endpoint like below.
You want to return ResponseEntity because you want control over the status and body which is returned within your endpoint code.

Click to see the Spingfox configuration used for this example

Now your generated OpenAPI doc contains responses with a $ref to ResponseEntity.

Springfox will also generate default responses for 201, 202, 400, 401, 403, 404, which you may never need.

Click to see the generated definition for ResponseEntity (it is quite long)

Continue reading →