Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger UI configuration with swagger-config.yaml

Tags:

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 ?

like image 251
Mahendra Kapadne Avatar asked Nov 21 '18 14:11

Mahendra Kapadne


People also ask

How do I load yaml in swagger UI?

Simply drag and drop your OpenAPI JSON or YAML document into the Swagger Editor browser window. File → Import URL. Paste the URL to your OpenAPI document.

Where do I put Swagger config yaml?

The swagger-config. yaml in the project root directory, if it exists, is baked into the application. configuration object passed as an argument to Swagger-UI (SwaggerUI({ ... })) configuration document fetched from a specified configUrl.

Can we customize swagger UI?

By default, Swagger UI uses BaseLayout , which is built into the application. You can specify a different layout to be used by passing the layout's name as the layout parameter to Swagger UI. Be sure to provide your custom layout as a component to Swagger UI.

Does Swagger support yaml?

Swagger definitions can be written in JSON or YAML. In this guide, we only use YAML examples, but JSON works equally well. A sample Swagger specification written in YAML looks like: swagger: "2.0"


1 Answers

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"
like image 146
yumingtao Avatar answered Sep 20 '22 05:09

yumingtao