Search code examples
node.jsswaggerswagger-uiapi-versioning

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.


Solution

  • 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'
          }
        ]
      }
    }