5

In my spring boot application, I am using swagger for documentation. I need to change the default http://localhost:8080/swagger-ui.html path to http://localhost:8080/docs/swagger-ui.html because I have the following controller which clashes with default swagger-ui path.

 @RequestMapping("/{coll}")
    public List<Map> getData(@PathVariable String coll){

        ....
        return list;
 }

I searched for so many resources (eg:https://github.com/springfox/springfox/issues/1443) and have suggested so many solutions but nothing works for me. Since this is very basic requirement in Swagger, what is the best way to change the swagger-ui.html default path to custom path?

Shashika
  • 1,606
  • 6
  • 28
  • 47

1 Answers1

0

You can change it with below code.Note I am using Apache CXF.So if you are jersey , please make change accordingly. Basically, you need to set basePath and Host in configuration.

        @Bean
        public Server rsServer() {
            JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
            endpoint.setBus(bus);
            endpoint.setAddress("/gbservice");
            endpoint.setServiceBeans(Arrays.<Object>asList(new HelloResourceImpl()));
            endpoint.setFeatures(Arrays.asList(swagger2Feature()));
            endpoint.setProvider(jsonProvider());
            return endpoint.create();
        }
        @Bean("swagger2Feature")
        public Feature swagger2Feature() {
            Swagger2Feature result = new Swagger2Feature();
            result.setTitle("Spring Boot + CXF + Swagger Example");
            result.setDescription("Spring Boot + CXF + Swagger Example description");
            result.setBasePath("/gb");
            result.setHost("http://localhost:8080/");
            result.setVersion("v1");
            result.setContact("Gaurao Burghate");
            result.setSchemes(new String[] { "http", "https" });
            result.setPrettyPrint(true);
            return result;
        }

So earlier my url was http://localhost:8080/services/swagger.json, after changing above configuration, URL become http://localhost:8080/services/gb/swagger.json

Note You must need to configure host and Also your context root should not be empty.