Search code examples
javaspringspring-bootswaggerspringfox

Springfox: Add global responses for some but not all endpoints


I have a select number of REST endpoints that share some responses. For example I have a controller with 3 methods with different paths:

POST
POST
DELETE

Last 2, POST and DELETE share 401 response. I want to describe it globally, without repeating myself, but it must not apply to first POST.

My question is: how do I globally describe the responses using Springfox for some but not all endpoints?

I've tried:

  1. Use .globalResponseMessage() in Docket API
  2. Creating several Docket beans and apply to select paths

First one distinguishes based on http verb and this does not work for me. Second breaks UI consistency and is quite weird to use.


Solution

  • According to Springfox github issue created, this is not possible at the moment.

    https://github.com/springfox/springfox/issues/2332