Test: add tests for empty enum validation#870
Test: add tests for empty enum validation#870Vaibhav701161 wants to merge 1 commit intojson-schema-org:mainfrom
Conversation
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
|
@jdesrosiers @gregsdennis and overall @json-schema-org/tsc is this the right reading of an empty |
|
There are several tests that validate a schema against (a |
|
@gregsdennis The point here is to assert what happens if you validate any value against a schema where |
|
Yes, it does that. However we should also test that empty enum is valid. Maybe these do that implicitly, but other places have a more direct test. |
|
@gregsdennis Can you point me to it? By doing searches on either 2020-12 metaschemas or tests, I don't see any empty enumeration being exercised. |
|
I'm not saying that enum is being tested anywhere else. I'm saying that the metaschema is used elsewhere to test keyword values. |
|
Ah, I see. @Vaibhav701161 maybe worth searching for what @gregsdennis is referring to and adding a test confirming |
Summary
This PR adds test cases covering the behaviour of:
{ "enum": [] }The tests are added for the following drafts:
Background
Starting from Draft 6, the JSON Schema validation specification relaxed the requirement that
enummust contain at least one element.Earlier drafts required this with a MUST requirement, but from Draft 6 onward this was changed to SHOULD (as defined in RFC 2119).
The draft 2020-12 validation meta-schema defines
enumas:Since there is no
minItemsconstraint, the meta-schema allows an empty array as a valid schema value.However, the current test suite does not contain any tests that exercise the case where
enumis an empty array.Interpretation
The tests added in this PR assume that an empty
enummatches no instances.The validation rule states:
If the array is empty, there is no element that can match the instance value.
Therefore, the tests expect all instances to be invalid.
If the intended behaviour is different, the expected results in the tests can be adjusted accordingly.
Files Changed
The following files are updated:
tests/draft6/enum.jsontests/draft7/enum.jsontests/draft2019-09/enum.jsontests/draft2020-12/enum.jsontests/v1/enum.jsonDraft 3 is not included because the specification explicitly required
enumto contain at least one element.Motivation
This case came up while implementing a lint rule in the
sourcemeta/coreproject that detects emptyenumvalues.For reference : sourcemeta/core#2287
Since this behaviour was not currently covered in the test suite, adding these tests helps clarify the expected validator behaviour.
cc @jviotti