如何在 Swagger 2.0 中对多个参数进行分组?多个、中对、参数、如何在

2023-09-08 09:18:33 作者:后会有妻

是否可以将多个参数分组以在多个路由中引用它们?

Is it possible to group multiple parameters to reference them in multiple routes?

例如,我在每条路线中都有我需要的参数组合.它们被定义为全局参数.如何将它们分组?

For example I have a combination of parameters which I need in every route. They are defined as global parameters. How can I group them?

我想到了这样的定义:

parameters:
  MetaDataParameters:
    # Meta Data Properties
    - name: id
      in: query
      description: Entry identification number
      required: false
      type: integer
    
    - name: time_start
      in: query
      description: Start time of flare
      required: false
      type: string
    
    - name: nar
      in: query
      description: Active region number
      required: false
      type: string

然后在我的路由中引用整个组:

And then reference the whole group in my route:

/test/:
  get:
    tags:
      - TEST
    operationId: routes.test
    parameters:
      - $ref: "#/parameters/MetaDataParameters"
    responses:
        200:
          description: OK

Swagger 2.0 可以做到这一点吗?

Is this possible with Swagger 2.0?

推荐答案

这在 Swagger 2.0 或 OpenAPI 3.0 中是不可能的.我已经为此打开了一个功能请求,并建议在未来的版本中使用:

This is not possible with Swagger 2.0 or OpenAPI 3.0. I've opened a feature request for this and it is proposed for a future version:

https://github.com/OAI/OpenAPI-Specification/issues/445