1

In swaggerhub I am trying to build a restful API. For which I have created n number of POJOs for request. I would like to represent them as references in other POJO example:

 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

I tried , but didn't work. Kindly suggest.

Raghuveer
  • 2,859
  • 7
  • 34
  • 66

1 Answers1

1

If ClientInformation is a merger of the EditClient and OtherDetails schemas, you need allOf:

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

If ClientInformation has properties that are instances of other schemas, you can $ref the property schemas as follows:

ClientInformation:
  type: object
  properties:
    notes:
      type: string
      example: This is a test
      description: A description
    foo:
      $ref: '#/definitions/EditClient'
    bar:
      $ref: '#/definitions/OtherDetails'
Helen
  • 87,344
  • 17
  • 243
  • 314