您可以从多个$ refs组成醒目的定义吗?

时间:2019-02-10 19:18:42

标签: swagger openapi

希望这个问题可以解决。

我正在建立一个规范的规范,我希望不仅能够重新使用定义的批发(即$ref的用途),而且能够从更简单的引用中构建那些定义。

例如,说我想将assetId的概念描述为参数和响应。我可以做这样的事情:

parameters:
  assetId:
    name: assetId
    in: path
    description: Identifier of the asset
    type: integer
responses:
  assetId:
    description: Identifier of the asset
    type: integer

并将#/parameters/assetId#/responses/assetId分别拉入各自的部分,但某些属性(即descriptiontype的重复性似乎仍然不可避免,< / p>

我想做的是将每个分解成原子块,然后主要从那些引用中组成参数和响应定义,例如:

swagger: "2.0"
descriptions:
  assetId:
    descriptions: Identifier of the assetId
schemas:
  assetId:
    type: integer
    format: int32
examples:
  assetId:
    example: 205778
paths:
  /assets/{assetId}:
    get:
      parameters:
        - name: assetId 
          in: path
          $ref: '#/schemas/assetId'
          $ref: '#/descriptions/assetId'
          $ref: '#/examples/assetId'    
      responses:
        '200'

并具有最后一个部分的评估结果:

  ...
  parameters:
    - name: assetId 
      in: path
      type: integer
      description: Identifier of the asset
      format: int32
      example: 205778 

...但是它不起作用;显然会抛出一个错误,提示我在$refs中有一个重复的密钥,但是我不知道该如何处理。谁能告诉我如何进行这种昂首阔步的定义?

注意:我正在使用swagger 2.0,因此,如果可以在其中使用它,那将是甜蜜的,但是即使只有在3.0中才有可能,我仍然想知道。

0 个答案:

没有答案
相关问题