4

I want to model a response object containing an array of different types of objects in swagger, something like this:

{
   "table": [
        {
          "user" : []
        },
        {
          "customer": []
        },
        {
           "employee": []
        }
    ]
}

I have tried a solution below but it wraps all the properties in a single object { [ { "user": [], "customer": [] } ] }.

  responses:
    200:
      schema:
        type: array
        items:
          type: object
          properties:
            user:
              type: array
              items:
                $ref: '#/definitions/User'
            customer:
              type: array
              items:
                $ref: '#/definitions/Customer'
            employee:
              type: array
              items:
                $ref: '#/definitions/Employee' 
1
  • 1
    This question has solutions for OpenAPI/Swagger 2.0. Commented Jun 28, 2017 at 13:24

1 Answer 1

4

That will be supported in the next release of OpenAPI spec (3.0) and here is the related discussion about this feature:

https://github.com/OAI/OpenAPI-Specification/issues/57

Here is an example (provided in the URL above):

{
  "oneOf": [
    { "$ref": "Cat" },
    { "$ref": "Dog" }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.