Search code examples
spring-bootswaggerspring-restcontrollerspringfoxspring-restdocs

Spring Boot Swagger: How to ignore certain API's from swagger based on spring profile?


Currently, there are certain private API's in my controller class which I need to ignore them in my production environment, whereas needed in the QA and Dev environments.

I'm using @ApiIgnore annotation from spring fox to achieve this on a global level. Is there a way where I can execute this annotation based on spring boot environment variable?

Or any other solution to tackle this problem ?


Solution

  • You can use

    @Autowired private Environment environment; 
    ....
    this.environment.getActiveProfiles();
    

    to get the current profile and then create Docket objects in your swagger configuration class based on the active profile.