How to change swagger-ui.html default path
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Changing the default Swagger UI path depends on which library is serving Swagger UI in your application. In modern Spring Boot projects using springdoc-openapi, the path is configurable with a property. In older Springfox-based setups, you often need a redirect or custom resource mapping instead.
Identify which Swagger library you are using
The path behavior is not universal because swagger-ui.html is a convention provided by a specific integration library, not by Spring Boot itself.
Two common cases are:
- '
springdoc-openapi, which usually supports property-based path customization' - Springfox, which historically exposed
/swagger-ui.htmlwith less direct configurability
The correct solution depends on which of those is in your dependency graph.
With springdoc-openapi, use the built-in property
If your project uses springdoc-openapi, you can change the UI path in application.properties:
Or in YAML:
After that, the UI is served at /docs instead of the default path. This is the cleanest modern answer because it is supported directly by the library.
With Springfox, a redirect is often the practical answer
Older Springfox setups commonly exposed the UI at /swagger-ui.html and did not always provide a simple one-line property to rename it. In that case, the common workaround is to create a controller or view-controller redirect:
This does not rename the underlying resource. It gives your application a friendlier custom route.
A WebMvcConfigurer redirect keeps things centralized
If you prefer a configuration-based approach:
This is useful when you want the path customization in one place rather than in a dedicated controller.
Remember that path changes are not a security control
Teams sometimes change the Swagger UI path for "security." That can reduce accidental discovery, but it is not real access control. If the docs should be restricted, protect them with authentication, authorization, or network-level controls.
Changing /swagger-ui.html to /docs can improve URL consistency. It should not be treated as a substitute for security configuration.
Test the generated assets after changing the route
After changing the entry path, open the UI in a browser and verify that the static assets and OpenAPI document still load correctly. A redirect that reaches the HTML page but breaks JavaScript bundles or the API docs URL is only a partial success.
Update reverse proxies and bookmarks too
Once the path changes, make sure related pieces stay aligned:
- reverse-proxy routing rules
- API gateway path rewrites
- developer documentation
- monitoring checks that probe the docs endpoint
A path change is easy in code and easy to forget everywhere else.
Common Pitfalls
- Applying
springdoc.swagger-ui.pathin a project that actually uses Springfox. - Assuming a new path automatically secures the documentation endpoint.
- Changing the route in the app but forgetting proxy or gateway rules.
- Redirecting to
/swagger-ui.htmlwithout verifying that the underlying resource is still enabled. - Mixing examples from different Swagger integration libraries.
Summary
- The right way to change the Swagger UI path depends on the library serving it.
- '
springdoc-openapisupports direct property-based path customization.' - Older Springfox setups often need a redirect or custom MVC mapping instead.
- Path changes improve organization, but they do not provide real security.
- After changing the route, update proxies, docs, and any monitoring that depends on the old path.
Related reading
- How to check errors from asynchronous Web Services calls
- How to check internet connection in alamofire?
- How To Check Response.statusCode in sendSynchronousRequest on Swift
- How to check whether a string is a valid HTTP URL?
- How to CNAME to Amazon API Gateway Endpoint
- How to combine host network with the default network in docker-compose
- How to configure external IP address of minikube dashboard?
- how to configure ingress to direct traffic to an https backend using https

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.