Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4062

how to do friendly base url for swagger 2.8.0

$
0
0

I'm trying to change base access url for API documentation. The url is "http://localhost:8080/swagger-ui.html". I want to get something like "http://localhost:8080/myapi/swagger-ui.html".

I use Springfox 2.8.0 Swagger, Java 8, Spring Boot 2.0The swagger configuration is:

@Configuration@EnableSwagger2public class SwaggerConfiguration {    @Bean    public Docket api(ServletContext servletContext) {        return new Docket(DocumentationType.SWAGGER_2)                .pathProvider(new RelativePathProvider(servletContext) {                    @Override                    public String getApplicationBasePath() {                        return "/myapi";                    }                })                .select()                .apis(RequestHandlerSelectors.any())                .paths(Predicates.not(PathSelectors.regex("/error")))                .build()                .useDefaultResponseMessages(false);    }}

Custom path provider had to help, but I still get access to api documentation by using url "http://localhost:8080/swagger-ui.html". If I use url "http://localhost:8080/myapi/swagger-ui.html", I get 404 error. Look at the screenshot below.

enter image description here


Viewing all articles
Browse latest Browse all 4062

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>