3

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

enter image description here

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.

Manoj Sethi
  • 1,898
  • 8
  • 26
  • 56
  • None of those links answers the question. I am not talking about multiple hosts. Where is the answer in your link https://github.com/OAI/OpenAPI-Specification/issues/408. Kindly read the question carefully – Manoj Sethi Jun 18 '20 at 06:27
  • 1
    Thanks for the efforts you have put in but that doesn't help. Below answer had served my purpose. – Manoj Sethi Jun 18 '20 at 06:50

1 Answers1

3

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'
      }
    ]
  }
}
MrMister
  • 2,456
  • 21
  • 31