Reputation: 4084
I am new to Swagger and have implemented Swagger UI with spring mvc, I want to disable UI on production/live environment. I am struggling to figure it out.
This is what I am using
SwaggerConfig.java
@Configuration
@EnableSwagger2
public class SwaggerConfig {
}
RestController.java
@RestController
@Api(value="city", description="Operations pertaining to City Data")
@RequestMapping(value="/v1/city")
public class RestController {
@ApiOperation(value = "View city by stateId or stateName")
@RequestMapping(value="/search",method=RequestMethod.POST)
public ResponseEntity<Object> getCityBystateId(@RequestBody StateDto stateDto,Model model){
}
}
Upvotes: 3
Views: 3872
Reputation: 5441
Another way is to use a reverse proxy to reject access to Swagger Api on your production environment.
In this case your production installation is exactly the same as your development/test environment (then more compliant with DevOps method) and you can continue to access your Swagger API with internal calls.
Upvotes: 5
Reputation: 28519
Look into the Spring's profile mechanism that lets you register different beans in different environments
When you bootstrap it according to doc, you can annotate your swagger config class on a class level with e.g. @Profile("dev")
, thus enabling the swagger configuration for the environment of your choice
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
}
Upvotes: 7