json schema: how to specify schema for array with two object types and min/max occurance for each type

59 Views Asked by At

I would like to define a JSON schema for an array that can contain two different objects (type A and type B). Only exactly the following combinations should be allowed:

[ A ]
[ A, B ]
[ B, A ]
[ B ]

my current schema draft

"myArray": {
    "type": "array",
    "minItems": 1,
    "maxItems": 2,
    "items": {
        "oneOf": [
            {
                "title": "TypeA",
                ...
            },
            {
                "title": "TypeB",
                ...
            }
        ]
    }
},

So far I have this schema, but this would also make an array with two times A valid. How can I specify the above condition?

0

There are 0 best solutions below