如何在 OpenAPI (Swagger) 中指定多个主机? [英] How do I specify multiple hosts in OpenAPI (Swagger)?

查看:89
本文介绍了如何在 OpenAPI (Swagger) 中指定多个主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的 OpenAPI 2.0 YAML 文件只有一个主机 URL:

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

推荐答案

OpenAPI 2.0 (Swagger 2.0) 仅支持具有多种方案(HTTP/HTTPS/etc.)的单个主机,因此您可以有效地拥有两个仅变化的主机在方案中:

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

最新版本,OpenAPI 3.0,支持多主机,具有不同的方案和基本路径:

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.

这篇关于如何在 OpenAPI (Swagger) 中指定多个主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆