Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger UI with Multiple Urls

Tags:

swagger-ui

I saw in the swagger ui documentation that you can provide a urls parameter which is:

An array of API definition objects ({url: "", name: ""}) used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed. Names and URLs must be unique among all items in this array, since they're used as identifiers.

I was hoping that this will give me a selector from which I can chose which of my yaml files to process. Unfortunately, it doesn't seem to do anything.

Here is my code:

window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
    urls: [
    {url:"http://test.dev/documentation/microservices/microservices.yaml",name:"All Microservices"},
    {url:"http://test.dev/documentation/microservices/plans.yaml",name:"Plans"},
    ],
    dom_id: '#swagger-ui',
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}

I'd also like to set the primaryName to All Microservices.

Any ideas on where I'm going wrong?

like image 569
zag2010 Avatar asked Jun 29 '17 04:06

zag2010


People also ask

How do I add multiple API to Swagger?

For example in spring (springfox-swagger) you need just to put the same tag on multiple API classes and it will merge them in one group in the swagger UI. @Api(value = "First API", tags = {"first-api"}) public class FirstApi { ... } @Api(tags = {"first-api"}) public class SecondApi { ... }

What is the default URL for Swagger UI?

By default, Swagger UI is accessible at /q/swagger-ui . The value / is not allowed as it blocks the application from serving anything else. A value prefixed with '/' makes it absolute and not relative. Once your application is started, you can go to http://localhost:8080/q/swagger-ui and play with your API.

How do I customize Swagger UI?

Customize the Swagger UI Using Style Sheet css under Content folder. Right click on SwaggerStyle. css file and select Embedded Resource option for Build Action as shown below. Here I added CSS class in SwaggerStyle.


1 Answers

The urls configuration option is supported in Swagger UI 3.0.18 and later.

You can use it instead of url like this:

window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
    urls: [
      {url: "https://path/to/api1.yaml", name: "API One"},
      {url: "https://path/to/api2.yaml", name: "API Two"},
    ],
    "urls.primaryName": "API Two"  // default document (if other than the first)
    ...
  })

Result:

"Select a definition" dropdown in Swagger UI

like image 65
Helen Avatar answered Sep 20 '22 12:09

Helen