add support to prefix all swagger http requests/resources
See original GitHub issue- What version of the library are you using? 2.9.2
What kind of issue is this?
- Feature Request.
we have the requirement to put all swagger documentation beneath a fix path. This first sounds close to an answer already given in How does one configure swagger-ui for non-springboot applications?. But the answer given there is to add some redirects to make it all work, but this is not going to work when you really only want to give explicit permission for one specific path e.g. /documentation/**
. we don’t care about the stuff after the path prefix, but it must all be beneath it - no redirects outside this path.
Its the same reasoning why spring boot has management.endpoints.web.base-path=/
to move all endpoints to a subpath. Actuator Web Endpoint Paths
I have done a little experiment and have this:
@SpringBootApplication
@EnableSwagger2
public class SpringfoxSwaggerApplication implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(SpringfoxSwaggerApplication.class, args);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/documentation/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry.addResourceHandler("/documentation/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Controller
@ApiIgnore
@RequestMapping("/documentation/swagger-resources")
public static class MyApiResourceController extends ApiResourceController {
public MyApiResourceController(SwaggerResourcesProvider swaggerResources) {
super(swaggerResources);
// how to set securityConfiguration and uiConfiguration? both are
// @Autowired by field injection :(
}
}
@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2).groupName("myapi").select().build();
}
// just a dummy controller
@RestController
@RequestMapping("/api")
public class MyController {
@GetMapping
public String home() {
return "hello world";
}
}
}
This allows me to redefine the RequestMapping
for ApiResourceController
. The startup works fine, and the UI stuff can also be loaded - but unfortunate these requests fail and I have no idea how to get them to work.
- http://localhost:8080/documentation/v2/api-docs?group=myapi
- http://localhost:8080/documentation/csrf
- http://localhost:8080/documentation/
Also setting springfox.documentation.swagger.v2.path=/documentation/v2/api-docs
does not help, it makes it even worse, as the it now tries to access http://localhost:8080/documentation/documentation/v2/api-docs?group=myapi
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top GitHub Comments
@imod thank you, will research and get back to you
@dilipkrish here it is: https://github.com/imod/SpringfoxSwagger-ContextPath
please let me know if there is anything I can help, it is really important for us…