Forum Discussion

nbo's avatar
nbo
Occasional Visitor
5 years ago
Solved

Have schemas with empty array

So i'm having a situation where a queue possibly has members. It's also posible that there is no members. This is kind of how i want to solve this problem: QueueMembers: type: object propert...
  • HKosova's avatar
    5 years ago

    Hi nbo,

     

    Your definition can be simplified into:

     

    QueueMembers:
      type: object
      properties:
        members:
          type: array
          items:
            $ref: '#/components/schemas/QueueMember'

    Both empty and non-empty arrays will validate against this definition.

     

    To require an array to be non-empty, add the minItems: 1 attribute.