Closed aMacDawg closed 2 years ago
Ok, I had to do word salad with my own question, but found another stackoverflow post that got closer to what I was trying to get at - validation on a string
field as opposed to validation on an array
field which is what the enum
approach seems to be for.
tl;dr - this works:
"channelType": {
"type": "string",
"default": "",
"title": "The channelType Schema",
"oneOf": [
{"enum": ["youtube", "twitch"]}
]
}
Closing this 🎉
Use-case: a property
channelType
can only expect the enums 'youtube' and 'twitch', any other values to thechannelType
key should return a validation error.JSON Schema snippet:
sample code:
Actual outcome: the channelType value could equal anything else ('facebook', 'sesame-street') and the validator will not return an error as expected
According to this stackoverflow post, the schema is formatted correctly for enums, and the npm-jsonschema docs did not specifically reference handling enums