In the application.properties of Spring Boot

springdoc.swagger-ui.path=/swagger-ui-custom.html

in your case it will be

springdoc.swagger-ui.path=/myapi/swagger-ui.html
Answer from Anil Dabas on Stack Overflow
🌐
GitHub
github.com › swagger-api › swagger-ui › issues › 3635
Altering default URL of API spec Swagger UI points to · Issue #3635 · swagger-api/swagger-ui
September 4, 2017 - The documentation mentions that you should 'change the default URL in the constructor' of Swagger UI to ensure other API specifications are filled in there. As I'd like to present my AP...
Author   Qqwy
Discussions

Change default API spec URL in Swagger UI - Stack Overflow
I'm using the Swagger Editor Docker image for defining my API specification and generate a nodejs server to run as stub api and serve the documentation for my API spec. I would like to know if it... More on stackoverflow.com
🌐 stackoverflow.com
c# - How do I change the Swagger default URL and use a custom one? - Stack Overflow
This compiles and works, however it is still using the same Swagger URL of: ... I think all this is doing is changing the location of the swagger.json because on the Swagger UI that comes up it is showing: More on stackoverflow.com
🌐 stackoverflow.com
default url in swagger UI
The url on the UI is keep defaulting to: https://petstore.swagger.io/v2/swagger.json How can I change it to something else? I prefer it to default to localhost:port/api/swagger.json option (grpc.ga... More on github.com
🌐 github.com
5
May 5, 2021
Default swagger UI to current instance - Swagger - ServiceStack Customer Forums
Hi wondering if there is any trick to getting /swagger-ui/index.html to reference the "local" /resources url by default rather than the petstore. More on forums.servicestack.net
🌐 forums.servicestack.net
0
July 7, 2017
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-ui › usage › configuration
Configuration | Swagger Docs
Swagger UI accepts configuration parameters in three locations. ... Parameters with dots in their names are single strings used to organize subordinate parameters, and are not indicative of a nested structure. For readability, parameters are grouped by category and sorted alphabetically. ... String="" means a String type with a default ...
🌐
Apidog
apidog.com › blog › swagger-ui-url
How to Change Swagger UI URL Defauth Path
February 5, 2026 - The URL parameter in the URL should point to the location of the OpenAPI specification file. There are many methods to change the default path of the Swagger UI URL.
🌐
Apidog
apidog.com › blog › how-to-use-swagger-ui-localhost
Swagger UI Localhost Tutorial: How to Use Swagger UI Locally?
February 5, 2026 - The default URL is http://localhost:/swagger where the port your API is running on locally. Enable Swagger in your startup code, launch the API project, and navigate to the /swagger endpoint to view the UI.
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-ui › usage › deep-linking
Deep Linking | Swagger Docs
I’m using Swagger UI in an application that needs control of the URL fragment. How do I disable deep-linking? This functionality is disabled by default, but you can pass deepLinking: false into Swagger UI as a configuration item to be sure.
Find elsewhere
🌐
Baeldung
baeldung.com › home › spring › spring boot › change swagger-ui url prefix
Change Swagger-UI URL prefix - Spring Boot
May 11, 2024 - Now let’s look at two approaches to customize the swagger-UI URL. We’ll begin with /myproject. As we’re already familiar with the many different properties in Spring, we’ll need to add the following properties to the application.properties file: springdoc.swagger-ui.disable-swagger-default-url=true springdoc.swagger-ui.path=/myproject
Top answer
1 of 2
23

I found the solution to this issue:

In the Configure section of Startup.cs I did the following:

First I added the folowing variable:

private readonly string swaggerBasePath = "api/app";

Next I configured the path using UseSwagger and UseSwaggerUI to use the swaggerBasePath variable:

            app.UseSwagger(c =>
            {
                c.RouteTemplate = swaggerBasePath+"/swagger/{documentName}/swagger.json";
            });

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/{swaggerBasePath}/swagger/v1/swagger.json", $"APP API - {version}");
                c.RoutePrefix = $"{swaggerBasePath}/swagger";
            });

Finally, I modified launchSettings.json to point to the new base path:

    "launchUrl": "api/app/swagger",

Then is was able to hit the Swagger page using:

https://localhost/api/app/swagger/index.html

I testing this with Nginx and it was able to route to the correct container.

I can easily tweak the base path (for instance to add the API version number) by simply modifying the swaggerBasePath variable and tweaking the launchSettings.json file to match the value of the variable.

Hopefully, this will help someone in the future.

2 of 2
6

(I am using .Net 6)

I needed this because I was facing issue in api gateway. So, What I did, I left my launch settings as it is.

launchsettings

"launchUrl": "studentservice/api/swagger",

I made these two changes in my Startup.cs file.

Note: Your launchsettings url and routeprefix url should match.

  • In ConfigureService Method, I have added SwaggerDoc
services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("student", new OpenApiInfo { Title = "Student Service Api", Version = "1.0" });
}
  • In Configure Method, I have added SwaggerDoc
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.)
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/student/swagger.json", "Student Services Api");
                    c.RoutePrefix = "studentservice/api/swagger";
                });
}

🌐
GitHub
github.com › grpc-ecosystem › grpc-gateway › issues › 2126
default url in swagger UI · Issue #2126 · grpc-ecosystem/grpc-gateway
May 5, 2021 - default url in swagger UI#2126 · Copy link · keith6014 · opened · on May 5, 2021 · Issue body actions · The url on the UI is keep defaulting to: https://petstore.swagger.io/v2/swagger.json How can I change it to something else?
Author   keith6014
🌐
ServiceStack
forums.servicestack.net › swagger
Default swagger UI to current instance - Swagger - ServiceStack Customer Forums
July 7, 2017 - Hi wondering if there is any trick to getting /swagger-ui/index.html to reference the "local" /resources url by default rather than the petstore.
🌐
GitHub
github.com › springfox › springfox › issues › 2396
Can't find Swagger UI endpoint · Issue #2396 · springfox/springfox
May 5, 2018 - With this I can go to /v2/api-docs to see the json version. However I can't find the UI endpoint. When going to http://localhost:8080/swagger-resources/ I only see: [ { "name": "default", "url": "/v2/api-docs", "swaggerVersion": "2.0", "location": "/v2/api-docs" } ] I've tried: http://localhost:8080/swagger-ui.html ·
Author   nWidart
🌐
Swagger
swagger.io › docs › specification › v2_0 › api-host-and-base-path
API Host and Base Path | Swagger Docs
basePath is the URL prefix for all API paths, relative to the host root. It must start with a leading slash /. If basePath is not specified, it defaults to /, that is, all paths start at the host root. Valid base paths: ... host and schemes can be omitted for a more dynamic association.
🌐
Quarkus
quarkus.io › guides › openapi-swaggerui
Using OpenAPI and Swagger UI - Quarkus
The Quarkus smallrye-openapi extension comes with a swagger-ui extension embedding a properly configured Swagger UI page. By default, Swagger UI is accessible at /q/swagger-ui.
🌐
FastAPI
fastapi.tiangolo.com › how-to › configure-swagger-ui
Configure Swagger UI - FastAPI
It defaults to [swagger_ui_default_parameters][fastapi.openapi.docs.swagger_ui_default_parameters]. Read more about it in the [FastAPI docs about how to Configure Swagger UI](https://fastapi.tiangolo.com/how-to/configure-swagger-ui/). """ ), ] = None, ) -> HTMLResponse: """ Generate and return the HTML that loads Swagger UI for the interactive API docs (normally served at `/docs`). You would only call this function yourself if you needed to override some parts, for example the URLs to use to load Swagger UI's JavaScript and CSS.
🌐
Swagger
swagger.io › docs › open-source-tools › swagger-ui › usage › installation
Installation | Swagger Docs
docker run -p 80:8080 -e BASE_URL=/swagger -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo docker.swagger.io/swaggerapi/swagger-ui · This will serve Swagger UI at /swagger instead of /. You can specify a different port via PORT variable for accessing the application, default is 8080.
🌐
GitHub
github.com › springdoc › springdoc-openapi › issues › 660
Question: How do I change the default url? · Issue #660 · springdoc/springdoc-openapi
May 11, 2020 - If I open swagger using the default link: /swagger-ui/index.html; swagger opens the petstore example, instead of the configuration stored in configUrl=/v3/api-docs/swagger-config.
Published   May 11, 2020
Author   SR-Lut3t1um
🌐
GitHub
github.com › swagger-api › swagger-ui › issues › 4751
Detecting default server url · Issue #4751 · swagger-api/swagger-ui
July 20, 2018 - Is your feature request related to a problem? We have different server urls: localhost, review apps, staging and production. Everytime one uses swagger ui, they have to pick correct server first. Currently default server url is the first...
Author   domenkozar