Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 346
Manoj Sethi Avatar asked Sep 13 '26 21:09

Manoj Sethi


1 Answers

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'
      }
    ]
  }
}
like image 115
MrMister Avatar answered Sep 16 '26 13:09

MrMister



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!