Islam Goher
Islam Goher

Reputation: 511

swagger-autogen: How to add multiple servers?

How to add multiple servers to swagger with swagger-autogen?

the documentation is providing only one host here

I want to do something like that:

const doc = {
  .
  .
  hosts: ['localhost:3000', 'localhost:5000'],
  .
  .
};

but when I did it, the base URL became http://localhost:3000localhost:5000/

is there any way to add multiple servers to swagger-autogen?

Upvotes: 1

Views: 1748

Answers (1)

Islam Goher
Islam Goher

Reputation: 511

yes, there is a way:

  1. Enable the OpenAPI v3 in the options here
const swaggerAutogen = require('swagger-autogen')({openapi: '3.0.0'});
  1. Remove host, basePath, and schemes from object doc
  2. Add the following array instead:
const doc = {
  .
  .
  servers: [
    {
      url: "http://localhost:3000/",
      description: "main server"
    },
    {
      url: "http://localhost:5000/",
      description: "the other server"
    }
  ],
  .
  .
};

it didn't exist in the documentation, but it works since the object doc is converted into a JSON object inside the file named swagger-output.json

Upvotes: 3

Related Questions