Description
Specification
From the latest JSON schema draft:
5.19. enum
This provides an enumeration of all possible values that are valid
for the instance property. This MUST be an array, and each item in
the array represents a possible value for the instance value. If
this attribute is defined, the instance value MUST be one of the
values in the array in order for the schema to be valid. Comparison
of enum values uses the same algorithm as defined in "uniqueItems"
(Section 5.15).
If I interpret the text in bold correctly then the JSON would be valid:
- if the attribute is omitted
- and if required is false
When running this in another JSON schema library this seems to hold true.
Testing
Running JSV with the following JSON structure:
{
"status": "running"
}
Against a schema like this one:
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"started", "stopped"
],
"required": false
}
}
}
Produces the following output
[ { uri: 'urn:uuid:b3801fd2-b377-4beb-b7ea-7e22a1e01a02#/status',
schemaUri: 'urn:uuid:dc175d99-1145-479c-b455-19fcf6cd30ad#/properties/status',
attribute: 'enum',
message: 'Instance is not one of the possible values',
details: [ 'started', 'stopped' ] } ]
If I however run the same schema against this JSON:
{
"ignore": "me"
}
It validates just fine.
Running this in json-schema produces the following output:
[status] does not have a value in the enumeration started, stopped