Search code examples
javaspringspring-bootswaggerswagger-ui

How to remove "swagger-ui" from Swagger URL?


I have below URL working in my Spring Boot project.

http://localhost:8080/swagger-ui/index.html

I would like to shorten it to something like

http://localhost:8080/docs/index.html

I have tried adding

springdoc.swagger-ui-path: /docs/index.html

to my application.yml but it will then redirect me to

http://localhost:8006/docs/swagger-ui/index.html

I have also tried making a custom controller that would redirect me like below but it still sends me to the same swagger-ui link.

public class SwaggerController {

    @RequestMapping("/docs/index.html")
    public void apiDocumentation(HttpServletResponse response) throws IOException {
        response.sendRedirect("/swagger-ui.html");
    }
}

Solution

  • You can set the entry URL for Swagger UI with properties (as you did).

    springdoc.swagger-ui.path=/docs
    

    This will work and you can for example provide the short form http://localhost:8006/docs in your documentation or Wiki pages.

    It will redirect the caller to the following URL:

    http://localhost:8006/docs/swagger-ui/index.html
    

    The last part of the above URL is hard-coded and can't be changed by configuration.

    I guess it is intentionally to respect the copyrights of the team behind Swagger UI. The same way you will not be able to remove the Swagger logo from the generated HTML.