覆盖“主机"和“basePath"在“/{path}"处等级等级、主机、basePath、quot

2023-09-07 13:43:54 作者:把少女心收藏

问题陈述:

出于奇怪"的原因,我们对 API 的所有操作都有不同的主机".我们有这样的 API:

For a "strange" reason, all our operations of an API have different "host". We have API like this:

操作 1:获取 https://host1:port1/api/resources操作 2:获取 https://host1:port2/api/resources/{id}操作 3:POST https://host2:port3/api/resources操作 4:POST https://host2:port4/api/resources/search

如果我们按原样使用 Swagger/OpenAPI,这意味着每个操作创建一个 Swagger/OpenAPI 规范,导致每个操作有一个 swagger-ui 页面,然后需要重新创建一个索引页面来列出所有API 的操作:-/这正是我们想要避免的.

If we use Swagger/OpenAPI as it is, it means creating one Swagger/OpenAPI specification per operation, resulting having one swagger-ui page per operation, and then, the need to re-create an index page to list all the operations of an API :-/ which is exactly what we want to avoid.

问题:

1/这个功能 - 在/{path}"级别覆盖host"和basePath" - 有意义吗?

1/ Does this feature - Override "host" and "basePath" at the "/{path}" level - make sense?

2/是否有人已经尝试在 swagger-ui 中实现此功能?

2/ Does someone already try to implement this feature in swagger-ui?

3/我可以/应该建议对 OpenAPI 进行这种更改吗?

3/ Could/should I propose this kind of change to OpenAPI?

欢迎任何其他有用的评论/评论;-)

Any other useful remarks/comments are welcome ;-)

推荐答案

OpenAPI 3.0 现在支持在路径或操作级别覆盖目标服务器:

Overriding the target server at the path or operation level is now supported in OpenAPI 3.0:

openapi: 3.0.0

servers:
  - url: https://my.api.com/v1

paths:
  /foo:
    # Override the server at path level
    servers:
      - url: https://another.server:8443/basePath

    get: ...
    post: ...

  /bar:
    get:
      # Override the server at operation level
      servers:
        - url: https://some.other.server/v2

    post: ...
 
精彩推荐
图片推荐