在单个架构中引用多个架构

时间:2019-01-10 11:11:02

标签: swagger-editor swaggerhub

在swaggerhub中,我试图构建一个宁静的API。为此,我创建了n个要请求的POJO。我想将它们表示为其他POJO示例中的引用:

 ClientInformation:
   type: object
   schema:
     $ref: '#/definitions/EditClient'
     $ref: '#/definitions/OtherDetails' #Duplicate mapping key error I see at this line
    properties:
      notes:
      type: string
      example: This is a test
      description: A description

我尝试了,,但是没有用。请提出。

1 个答案:

答案 0 :(得分:0)

如果ClientInformationEditClientOtherDetails模式的合并,则需要allOf

ClientInformation:
  allOf:
    - $ref: '#/definitions/EditClient'
    - $ref: '#/definitions/OtherDetails'
    - type: object
      properties:
        notes:
          type: string
          example: This is a test
          description: A description

如果ClientInformation具有作为其他架构实例的属性,则可以$ref如下所示的属性架构:

ClientInformation:
  type: object
  properties:
    notes:
      type: string
      example: This is a test
      description: A description
    foo:
      $ref: '#/definitions/EditClient'
    bar:
      $ref: '#/definitions/OtherDetails'