/components/parameters 中的 openApi 3 allOf

sel*_*ect 3 swagger swagger-editor openapi

我正在尝试使用 open api 3 创建一个 swagger 文档,但是当我尝试allOf在参数定义中使用关键字时出现错误

components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        type: string
        format: int65
    dataSourceID:
      allOf:
        - $ref: '#/components/parameters/idParam'
        - name: dataSourceID
          description: ID of the data source
Run Code Online (Sandbox Code Playgroud)

components.parameters['dataSourceID'] 处的架构错误

不应该有额外的属性

附加属性:allOf

是否可以重用另一个参数的值?也许以不同的方式?

Hel*_*len 5

allOf仅在Schema Objects 中支持,用于实现模型组合和继承allOf在不支持parameterspaths和其他地方。

在您的示例中,您最多可以为int65两个参数定义一个可重用的架构并引用它:

openapi: 3.0.0
...

components:
  schemas:
    int65:
      type: string
      format: int65

  parameters:
    idParam:
      name: id
      in: path
      description: ID of the boxx
      required: true
      schema:
        $ref: '#/components/schemas/int65'   # <-----
    dataSourceID:
      name: dataSourceID
      in: path
      description: ID of the data source
      required: true
      schema:
        $ref: '#/components/schemas/int65'   # <-----
Run Code Online (Sandbox Code Playgroud)

  • @select 随意在 OpenAPI 规范存储库中提交功能请求:https://github.com/OAI/OpenAPI-Specification/issues (2认同)