The URL of the API definiton is displayed in the top bar of Swagger UI – in your example it's

/v2/api-docs?group=full-petstore-api

So the full URL appears to be

http://localhost:8080/v2/api-docs?group=full-petstore-api

In newer versions of Swagger UI, the link to the API definition is often displayed below the API title, so you can right-click the link and Save As.


If your Swagger UI does not have a visible link to the API definition, view the page source and look for the url parameter, such as:

const ui = SwaggerUIBundle({
  url: "https://petstore.swagger.io/v2/swagger.json",     // <-------
  dom_id: '#swagger-ui',

If you don't see the url or if url is a code expression, open the browser dev tools, switch to the Network tab and disable caching. Then refresh the page and search for the API definition file (swagger.json, swagger.yaml, api-docs or similar) among HTTP requests. You can filter by XHR to narrow down the list.


Another way to find the actual url is to use the browser console and evaluate one of the following values, depending on your UI version:

  • Swagger UI 3.x and later:

    ui.getConfigs().url
    
  • Swagger UI 2.x:

    swaggerUi.api.url
    


Sometimes the OpenAPI definition may be embedded within a .js file – in this case take this file and strip out the extra parts.

Answer from Helen on Stack Overflow
Top answer
1 of 12
225

The URL of the API definiton is displayed in the top bar of Swagger UI – in your example it's

/v2/api-docs?group=full-petstore-api

So the full URL appears to be

http://localhost:8080/v2/api-docs?group=full-petstore-api

In newer versions of Swagger UI, the link to the API definition is often displayed below the API title, so you can right-click the link and Save As.


If your Swagger UI does not have a visible link to the API definition, view the page source and look for the url parameter, such as:

const ui = SwaggerUIBundle({
  url: "https://petstore.swagger.io/v2/swagger.json",     // <-------
  dom_id: '#swagger-ui',

If you don't see the url or if url is a code expression, open the browser dev tools, switch to the Network tab and disable caching. Then refresh the page and search for the API definition file (swagger.json, swagger.yaml, api-docs or similar) among HTTP requests. You can filter by XHR to narrow down the list.


Another way to find the actual url is to use the browser console and evaluate one of the following values, depending on your UI version:

  • Swagger UI 3.x and later:

    ui.getConfigs().url
    
  • Swagger UI 2.x:

    swaggerUi.api.url
    


Sometimes the OpenAPI definition may be embedded within a .js file – in this case take this file and strip out the extra parts.

2 of 12
28

Though it's already been answered and it's the correct one, I thought I shall post the much detailed version of it.. Hope this helps,

  1. If you do have the swagger json file which you feed to the swagger UI, then to generate .yaml file just click on the below link copy-paste your json in the editor and download the yaml file. This is a straight forward method

link : https://editor.swagger.io/#

  1. Now the second way where you don't have any swagger json file then the following steps should help,

Open the swagger ui, inspect (Shift+Ctrl+i), refresh the page and you will get the tabs like below

Choose XHR or All tab under Network tab, check for the file api-doc?group=* and click subtab response. *Now copy the content of ap-doc?group.** file and use the same editor link to convert to yaml file

link : https://editor.swagger.io/#

🌐
Swagger
swagger.io › docs › open-source-tools › swagger-ui › usage › installation
Installation | Swagger Docs
docker run -p 80:8080 -e SWAGGER_JSON_URL=https://petstore3.swagger.io/api/v3/openapi.json docker.swagger.io/swaggerapi/swagger-ui
Discussions

How to use local json file in swagger-ui documentation - Stack Overflow
After starting the docker instance ... swagger-ui-builder, accessing http://192.168.xx.xx/ does not display the documentation. Attaching the screenshot for reference. Please help me to resolve this. ... Did the solution work? What did you do? I’m having the same problem, everything work in my local iis but when I move it to remote server it does not work. It throws cannot read file error. ... The sample provided in the question cannot work at all (missing coma and spec is not a SwaggerUI ... More on stackoverflow.com
🌐 stackoverflow.com
Using a source swagger.json Url directly from URL parameter
Unless I'm mistaken, I haven't found a way to create a URL that would encapsulate a target swagger.json. I think it would be useful to have this possibility: one could point people directly to an A... More on github.com
🌐 github.com
2
November 2, 2015
How to automatically save generated /swagger.json into a local file
Hello, I am new here. I am using swagger core to generate my swagger specification files. I am also using swagger ui dist folder to access... More on community.smartbear.com
🌐 community.smartbear.com
3
0
July 27, 2019
Customize Swagger UI and JSON URLs using Swashbuckle and .NET CORE 3.1 - Stack Overflow
NET Core 3.1 Web application with Swashbuckle.AspNetCore for swagger. I want to have a custom name added to both my swagger UI URL and swagger JSON URL. We have a proxy which redirects to different... More on stackoverflow.com
🌐 stackoverflow.com
🌐
FastAPI
fastapi.tiangolo.com › how-to › configure-swagger-ui
Configure Swagger UI - FastAPI
This is normally done automatically by FastAPI using the default URL `/openapi.json`. Read more about it in the [FastAPI docs for Conditional OpenAPI](https://fastapi.tiangolo.com/how-to/conditional-openapi/#conditional-openapi-from-settings-and-env-vars) """ ), ], title: Annotated[ str, Doc( """ The HTML `<title>` content, normally shown in the browser tab. Read more about it in the [FastAPI docs for Custom Docs UI Static Assets](https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/) """ ), ], swagger_js_url: Annotated[ str, Doc( """ The URL to use to load the Swagger UI JavaScript.
🌐
Google Groups
groups.google.com › g › swagger-swaggersocket › c › RkfkrRFRnNA
How to view local JSON file in Swagger UI
The first being simply cloning the UI repo and placing my JSON file in the dist folder, then opening dist/index.html in a browser and searching for my file through the UI by searching "../my_swagger.json".
🌐
Microsoft Learn
learn.microsoft.com › en-us › aspnet › core › tutorials › getting-started-with-swashbuckle
Get started with Swashbuckle and ASP.NET Core | Microsoft Learn
The preceding code adds the Swagger ... version of the Swagger UI tool. Launch the app and navigate to https://localhost:<port>/swagger/v1/swagger.json....
Top answer
1 of 3
2

The sample provided in the question cannot work at all (missing coma and spec is not a SwaggerUI property).

To show your swagger.json file which is in the same folder as index.html you just need to replace url = "http://petstore.swagger.io/v2/swagger.json" by url = "swagger.json"; in index.html.

Original index.html

      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        url = "http://petstore.swagger.io/v2/swagger.json";
      }

      [...]

      window.swaggerUi = new SwaggerUi({
        url: url,
        dom_id: "swagger-ui-container",
        supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
        onComplete: function(swaggerApi, swaggerUi){
          if(typeof initOAuth == "function") {
            initOAuth({
              clientId: "your-client-id",
              clientSecret: "your-client-secret-if-required",
              realm: "your-realms",
              appName: "your-app-name",
              scopeSeparator: ",",
              additionalQueryStringParams: {}
            });
          }

Modified:

      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        url = "swagger.json";
      }

      [...]

      window.swaggerUi = new SwaggerUi({
        url: url,
        dom_id: "swagger-ui-container",
        supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
        onComplete: function(swaggerApi, swaggerUi){
          if(typeof initOAuth == "function") {
            initOAuth({
              clientId: "your-client-id",
              clientSecret: "your-client-secret-if-required",
              realm: "your-realms",
              appName: "your-app-name",
              scopeSeparator: ",",
              additionalQueryStringParams: {}
            });
          }
2 of 3
2

Here was a solution I found here (pretty quick and painless if you have node installed):

  1. With Node, globally install package http-server npm install -g http-server

  2. Change directories to where json is located, and run the command http-server --cors (CORS has to be enabled for this to work)

  3. Open swagger ui (i.e. dist/index.html)

  4. Type http://localhost:8080/my.json in input field and click "Explore"

🌐
Medium
medium.com › @vamsidogiparthi › learn-how-to-host-swagger-ui-and-swagger-json-to-custom-endpoint-06dc5c232104
Learn how to host Swagger UI and Swagger JSON to custom endpoint | by Vamsi Dogiparthi | Medium
July 8, 2024 - // an web application middleware method to allow you // to use the nSwag open api generated swagger json document // default hosting local url: http://localhost:{portnumber}/swagger/v1/swagger.json app.UseOpenApi((settings) => { settings.Path ...
Find elsewhere
🌐
GitHub
github.com › swagger-api › swagger-ui › issues › 1719
Using a source swagger.json Url directly from URL parameter · Issue #1719 · swagger-api/swagger-ui
November 2, 2015 - Unless I'm mistaken, I haven't found a way to create a URL that would encapsulate a target swagger.json. I think it would be useful to have this possibility: one could point people directly to an API documentation page. (ex. http://petstore.swagger.io/target/http://myrestapi/) Right now I encapsulate the swagger-ui project in each of my project, but I think I'd be better off setting up a web instance of swagger-ui and let people use this instance to query my project's swagger.json.
Author   nodje
🌐
Tibco
docs.tibco.com › pub › mdm › 9.2.0 › doc › html › GUID-E104EC0C-C433-48D5-A22F-7061E4BD1409.html
Generating a Swagger JSON File
On the Swagger UI, click the http://mdmhost:port/rest/v2/api-docs link to generate a Swagger.json file.
Top answer
1 of 3
1
Generally speaking, swagger-core generates the API definition at runtime (just like another API endpoint). It's a bit unclear from your description how your application works. so: If your UI is intended to run alongside the API, you can simply point the UI to the generated definition at runtime. That way it's always up to date and there's no issue. If you need the UI to be completely independent from the application, you can use the maven plugin we have to generate the definition at build time and put it wherever you need. More information can be found at https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-maven-plugin.
2 of 3
0
Thank you for replying RonRatovsky  I would like to point the UI to the generated definition at runtime but i get a "Failed to Load spec". This may be because to access the definition, there must be some authentication and custom header added. I am using a url like this on index.html      window.onload = function() { // Build a system const ui = SwaggerUIBundle({ url: "https://localhost:8443/example.swagger.io/api/v1/swagger.json?Platform-TenantId=default&&Authorization=Basic bWlmb3M6cGFzc3dvcmQ=", dom_id: '#swagger-ui', validatorUrl : false, presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" })   Also the try it out buttons on the swagger ui do not function when i use the path url to the locally saved swagger spec. I think it may be due to the authentication and header to be added on every request inorder to access to the server.  How can i resolve this please?
🌐
Apidog
apidog.com › blog › swagger-ui-url
How to Change Swagger UI URL Defauth Path
February 5, 2026 - http://localhost:8080/swagger-ui/?configUrl=/path/to/your/config.json ... It enables deep linking to individual operations or tags in the API documentation. It is beneficial when sharing direct links to specific parts of the documentation. ...
🌐
npm
npmjs.com › package › swagger-ui-express
swagger-ui-express - npm
To render a link to the swagger document for downloading within the swagger ui - then serve the swagger doc as an endpoint and use the url option to point to it: const express = require('express'); const app = express(); const swaggerUi = require('swagger-ui-express'); const swaggerDocument = require('./swagger.json'); var options = { swaggerOptions: { url: "/api-docs/swagger.json", }, } app.get("/api-docs/swagger.json", (req, res) => res.json(swaggerDocument)); app.use('/api-docs', swaggerUi.serveFiles(null, options), swaggerUi.setup(null, options));
      » npm install swagger-ui-express
    
Published   May 31, 2024
Version   5.0.1
🌐
Codeshare
codeshare.co.uk › blog › how-to-get-the-swagger-json-file-from-a-web-api
How to get the swagger JSON file from a Web API | CodeShare by Paul Seal
July 26, 2018 - The person requesting it should know how to get it from the swagger url, but if you do have to provide the swagger.json file, here is how you do it.
🌐
Microsoft Learn
learn.microsoft.com › en-us › aspnet › core › tutorials › web-api-help-pages-using-swagger
ASP.NET Core web API documentation with Swagger / OpenAPI | Microsoft Learn
February 23, 2026 - The OpenAPI specification is a document that describes the capabilities of your API. The document is based on the XML and attribute annotations within the controllers and models. It's the core part of the OpenAPI flow and is used to drive tooling such as SwaggerUI. By default, it's named openapi.json.
🌐
GitHub
github.com › scottie1984 › swagger-ui-express › issues › 194
swagger.json link not available with spec object · Issue #194 · scottie1984/swagger-ui-express
June 9, 2020 - AFAIK there are (at least) two ways to setup swagger-ui-express: providing the swagger.json file url var options = { swaggerOptions: { url: 'http://petstore.swagger.io/v2/swagger.json' } } app.use('/api-docs', swaggerUi.serve, swaggerUi....
Author   jbaris
🌐
GitHub
github.com › swagger-api › swagger-ui › issues › 1110
how to load local .json file? #1110 - swagger-api/swagger-ui
April 1, 2015 - I can load it through URL, but when I try to change the index.html to local json, it doesn't work, any idea how I can debug further? BTW, I use swagger-maven-plugin to generate the json, so there are multiple json files: service.json, users.json.... ..... window.swaggerUi = new SwaggerUi({ spec: "file://work/swagger-maven-example/generated/swagger-ui/service.json", dom_id: "swagger-ui-container", .....
Author   hongxingli
🌐
SmartBear Community
community.smartbear.com › smartbear community › swagger open source tools › swagger open source tools questions
Creating SwaggerUI with pre existing swagger.json document | SmartBear Community
Now when you access https://pre-existing-swagger.com/static/api.html, SwaggerUI will render the swagger.json file. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Api</title> <link rel="stylesheet" href="//unpkg.com/swagger-ui-dist@3.26.0/swagger-ui.css" /> <script ...
🌐
Swagger
swagger.io › docs › specification › v2_0 › basic-structure
Basic Structure | Swagger Docs
UIVisualize OpenAPI Specification definitions in an interactive UI. ... API DesignAPI DevelopmentAPI DocumentationAPI TestingAPI Mocking and VirtualizationAPI GovernanceAPI MonitoringOpenAPI & Swagger ... OAS 2 This page applies to OpenAPI Specification ver. 2 (fka Swagger). To learn about the latest version, visit OpenAPI 3 pages. Swagger definitions can be written in JSON or YAML.