3

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 ?

shoaib1992
  • 410
  • 1
  • 8
  • 26

1 Answers1

2

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.

Anand Kulkarni
  • 1,131
  • 1
  • 7
  • 7
  • Thanks it worked. if (Arrays.stream(env.getActiveProfiles()).anyMatch(e -> (e.equalsIgnoreCase("dev")))) { requestHandlerSelector = and(not(withClassAnnotation(ApiIgnore.class)), not(withMethodAnnotation(ApiIgnore.class))); } else { requestHandlerSelector = any(); } – shoaib1992 Apr 12 '18 at 18:51
  • @AnandKuklkarni Can you please take a look at this question: https://stackoverflow.com/questions/49835394/swagger-springfox-custom-sort-comparator-to-order-the-apis – shoaib1992 Apr 19 '18 at 06:03