简体   繁体   中英

Swagger UI Express with API Versioning

I am using swagger-ui-express and swagger-jsdoc for API Documentation of my node app. The point here is that I have two versions of API in my App and I want to document both of them. I have seen that in .NET Core there is an option available to define the specs and choose one from a dropdown in top bar. I am looking for a similar solution

在此处输入图像描述

As a dropdown can be seen in top bar I want similar via swagger-ui-express. Is it possible or if anybody has implemented the same for API Versioning?

Looking forward to your responses.

The solution I propose is not specific to API versioning, but you can have a dropdown of URLs the end-user can choose from. According to the docs , you would need to pass a swaggerOptions object:

const swaggerOptions = {
  explorer: true,
  swaggerOptions: {
    urls: [
      {
        url: 'https://v1/swagger.json',
        name: 'v1'
      },
      {
        url: 'https://v2/swagger.json',
        name: 'v2'
      }
    ]
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM