I am using Springfox Swagger2 with Spring boot 1.5.9.
I can access swagger UI on this link.
http://localhost:8090/swagger-ui.html
How can I change it to be available on following URL?
http://localhost:8090/my/custom/path/swagger-ui.html
@EnableSwagger2
public class Configuration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("my.favorite.package"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo()).useDefaultResponseMessages(false);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("My title").version("1.0")
.contact(new Contact("Blah", "blah.com", "[email protected]")).build();
}
}
You can change default swagger-ui path programmatically using ApplicationListener<ApplicationPreparedEvent> . The idea is simple - override springdoc. swagger-ui. path=/custom/path before your Spring Boot application starts.
Once your application is started, you can go to http://localhost:8080/q/swagger-ui and play with your API. You can visualize your API's operations and schemas.
The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .
Springfox Swagger had always been kinda dirty solution with a lot of unclearness and bugs, but by now (2021 Q4) it hadn't been updated for more than a year.
The final straw was the fact that Springfox Swagger 3.0 doesn't work anymore with Spring Boot 2.6.x.
So, if you reading this, please, consider switching over to https://springdoc.org/ instead.
It's a pretty straightforward conversion and they do a great job of documenting it. https://springdoc.org/#migrating-from-springfox.
I've found a working solution for Springfox 3.0.0 here:
springfox:
documentation:
swaggerUi:
baseUrl: /documentation
openApi:
v3:
path: /documentation/v3/api-docs
swagger:
v2:
path: /documentation/v2/api-docs
Configuration above will change base-path for Swagger endpoints to /documentation
without any redirects and other crutches.
It is sad that these configurations is missing in the docs tho.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With