Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 705
user2598740 Avatar asked Nov 14 '16 07:11

user2598740


2 Answers

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

But OpenAPI 3.x 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.

like image 94
Helen Avatar answered Nov 17 '22 10:11

Helen


It is now possible in OpenApi 3.0

Here is a description:

Multiple hosts are supported in OpenAPI 3.0. 2.0 supports only one host per API specification (or two if you count HTTP and HTTPS as different hosts). A possible way to target multiple hosts is to omit the host and schema from your specification and serve it from each host. In this case, each copy of the specification will target the corresponding host.

like image 2
waletoye Avatar answered Nov 17 '22 10:11

waletoye