24

As per swagger documentation,

Swagger-UI accepts configuration parameters in four locations.

From lowest to highest precedence:

  1. The swagger-config.yaml in the project root directory, if it exists, is baked into the application
  2. configuration object passed as an argument to Swagger-UI (SwaggerUI({ ... }))
  3. configuration document fetched from a specified configUrl
  4. configuration items passed as key/value pairs in the URL query string

I have tried to put swagger-config.yaml in root pat of application but its not working.

I have followed swagger Installation steps and its working correct. but steps for swagger custom config is not working. I have kept files as below,

 swagger-ui
   |--swagger-config.yaml
   |--index.html

swagger-config.yaml

url: "https://petstore.swagger.io/v2/swagger.json"
dom_id: "#swagger-ui"
validatorUrl: "https://online.swagger.io/validator"
oauth2RedirectUrl: "http://localhost:3200/oauth2-redirect.html"

index.html

// Begin Swagger UI call region
      const ui = SwaggerUIBundle({
        //url: "https://petstore.swagger.io/v2/swagger.json",
        //dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout"
      })

Any idea if I am missing anything ?

Mahendra Kapadne
  • 426
  • 1
  • 3
  • 10
  • How do you run Swagger UI - open the page from the file system, or from a web server, or using `npm start`? – Helen Nov 21 '18 at 16:59
  • I tried it on JBoss as well as file system. – Mahendra Kapadne Nov 21 '18 at 17:01
  • You say it is not working. Could you please elaborate? When you look at your web browser's console, do you see any error messages? When you look at your browser's network console, do you see any successful attempts to download https://petstore.swagger.io/v2/swagger.json? – Erunafailaro Feb 20 '20 at 08:20
  • @MahendraKapadne did you solve your problem? I'm running into the exact same issue - swagger-ui does not pick up my swagger-config.yaml I put into the swagger-ui root directory. – Bernd May 01 '20 at 11:55
  • @Bernd For time being, I had hard coded relative URI in url. – Mahendra Kapadne May 01 '20 at 12:40
  • @MahendraKapadne - could you elaborate on how you hard-coded the relative URI in the url? – andrewniesen May 14 '20 at 13:45

2 Answers2

5

As mentioned in this Github's issue thread now only .json files are accepted for conf. Probably too late but it can help looking for the answer at November 2021.

felixminom
  • 51
  • 1
  • 2
2

I also have this issue. From the document, it seems we don't need to config anything in index.html if use swagger-config.xml, actually, it doesn't work from my side, I have not find the reason. But if use configUrl instead, it works.

// Begin Swagger UI call region
const ui = SwaggerUIBundle({
  //url: "https://petstore.swagger.io/v2/swagger.json",
  //dom_id: '#swagger-ui',
  configUrl: "../swagger-config.yaml",
  deepLinking: true,
  presets: [
    SwaggerUIBundle.presets.apis,
    SwaggerUIStandalonePreset
  ],
  plugins: [
    SwaggerUIBundle.plugins.DownloadUrl
  ],
  layout: "StandaloneLayout"
})

And it can be configured to support the array.

---
urls:
 - url: "https://petstore.swagger.io/v2/swagger.json"
   name: "url1"
   
 - url: "https://petstore.swagger.io/v2/swagger.json"
   name: "url2"
yumingtao
  • 81
  • 4