Mahendra Kapadne
Mahendra Kapadne

Reputation: 426

Swagger UI configuration with swagger-config.yaml

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 ?

Upvotes: 24

Views: 19294

Answers (2)

felixminom
felixminom

Reputation: 51

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.

Upvotes: 5

yumingtao
yumingtao

Reputation: 89

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"

Upvotes: 3

Related Questions