Forum Discussion

BostonKevin's avatar
BostonKevin
Contributor
6 years ago

Can You Define a Response Consisting of an Array With Two Different Objects?

Hi!   It is easy to define a response that consists of an array made up of several objects.  Is it possible to define a response consisting of two separate objects?   When I have attempted to...
  • HKosova's avatar
    HKosova
    6 years ago

    BostonKevin wrote:

    Data is packed into two distinct objects that are in the same array.


    That's exactly how the first example with oneOf works.

     

     

    "type": "array",
    "items": {
    "oneOf": [
    { "$ref": "#/components/schemas/Schema1" },
    { "$ref": "#/components/schemas/Schema2" }
    ]
    }

    means that the array contains Schema1 and/or Schema2.

  • HKosova's avatar
    HKosova
    6 years ago

    Correct.