How do I specify multiple hosts in OpenAPI (Swagger)?

user2598740 picture user2598740 · Nov 14, 2016 · Viewed 11.1k times · Source

Right now my OpenAPI 2.0 YAML file has only one host URL:

host: petstore.test.com
basePath: /

Can I use multiple hosts like this?

host1: petstore.test.com
host2: petstore1.test.com
host3: petstore2.dev.com

Answer

Helen picture Helen · Nov 15, 2016

OpenAPI 2.0 (Swagger 2.0) only supports a single host with multiple schemes (HTTP/HTTPS/etc.), so you can effectively have two hosts that only vary in the scheme:

host: petstore.test.com
schemes:
  - http
  - https

The latest version, OpenAPI 3.0, supports multiple hosts with different schemes and base paths:

servers:
  - url: https://petstore.prd.com
    description: Production server

  - url: {scheme}://petstore.dev.com/subpath
    description: Development server
    templates:
      scheme:
        enum:
          - http
          - https
        default: https

For more examples, see this answer.