Forum Discussion

sanghvi_yash's avatar
sanghvi_yash
New Member
4 years ago

allOf to include main object and more array of schemas within it

I am trying to return a Posts object with Images and Videos with it.
Posts, Images and Videos are all separate objects.
Posts may or may not have Images and Videos associated to it.
I am trying to create a new response in the following way:

    PostsResponse:
      allOf:
      - $ref: '#/components/schemas/Post'
      - Images:
        type: array
        items:
          $ref: '#/components/schemas/Image'
      - Videos:
        type: array
        items:
          $ref: '#/components/schemas/Video'

While trying to do the above thing following error is thrown
should NOT have additional properties
additionalProperty: Images
same error for Videos.

Please help

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Try this:

        PostsResponse:
          allOf:
          - $ref: '#/components/schemas/Post'
          - properties:
              Images:
                type: array
                items:
                  $ref: '#/components/schemas/Image'
              Videos:
                type: array
                items:
                  $ref: '#/components/schemas/Video'