cancel
Showing results for 
Search instead for 
Did you mean: 

Have schemas with empty array

SOLVED
Highlighted
nbo
Occasional Visitor

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
  properties:
    members:
      oneOf:
        - type: array
          items:
            allOf:
              - $ref: '#/components/schemas/QueueMember'
        - type: array

The editor doesn't give me any errors, but the example schema shows this:
image.png

So, am i thinking of this thing wrongly?
Should people just accept that, if an array of object is a possible option, than it's also possible it's not there?

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Have schemas with empty array

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.

 


Helen Kosova
SmartBear Technical Writer
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

1 REPLY 1
Moderator

Re: Have schemas with empty array

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.

 


Helen Kosova
SmartBear Technical Writer
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post