František Žiačik
František Žiačik

Reputation: 7612

Json schema "not in" enum type?

I'd like to use oneOf schemas which differ only by value of xyType property. I'd like to have two of them: one where the xyType is set to "1" and the second one where xyType is any other value. Can this be done using json schemas?

"oneOf": [
    {
        "properties": {
            "xyType": "enum": ["1"],
            "whatever" : "string"
        },
        "type": "object"
    },
    {
        "properties": {
            "xyType": "enum": [], /// NOT "1"?
            "whatever" : "string"
        },
        "type": "object"
    }
]

Upvotes: 5

Views: 4215

Answers (1)

cloudfeet
cloudfeet

Reputation: 12863

There's a not operator, and the enum keyword, and you can use them together, like

{
    "not": {
        "enum": ["1"]
    }
}

Upvotes: 14

Related Questions