Skip to content

Commit 983c14f

Browse files
authored
Property support the empty enum in 2019-09 and 2020-12 (#747)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 2d2b843 commit 983c14f

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/compiler/default_compiler_draft4.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,11 @@ auto compiler_draft4_validation_enum(const Context &context,
20592059
return {};
20602060
}
20612061

2062+
if (schema_context.schema.at(dynamic_context.keyword).empty()) {
2063+
return {make(sourcemeta::blaze::InstructionIndex::AssertionFail, context,
2064+
schema_context, dynamic_context, ValueNone{})};
2065+
}
2066+
20622067
if (schema_context.schema.at(dynamic_context.keyword).size() == 1) {
20632068
return {
20642069
make(sourcemeta::blaze::InstructionIndex::AssertionEqual, context,

src/evaluator/evaluator_describe.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ auto describe(const bool valid, const Instruction &step,
216216
const sourcemeta::core::JSON &target{get(instance, instance_location)};
217217

218218
if (step.type == sourcemeta::blaze::InstructionIndex::AssertionFail) {
219+
if (keyword == "enum") {
220+
std::ostringstream message;
221+
message << "The " << type_name(target.type())
222+
<< " value was not expected to validate against the empty "
223+
"enumeration";
224+
return message.str();
225+
}
226+
219227
if (keyword == "contains") {
220228
return "The constraints declared for this keyword were not satisfiable";
221229
}

test/evaluator/evaluator_2019_09.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4819,5 +4819,61 @@
48194819
"The object value was not expected to define unevaluated properties"
48204820
]
48214821
}
4822+
},
4823+
{
4824+
"description": "empty_enum_string",
4825+
"schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "enum": [] },
4826+
"instance": "foo",
4827+
"valid": false,
4828+
"fast": {
4829+
"pre": [
4830+
[ "AssertionFail", "/enum", "#/enum", "" ]
4831+
],
4832+
"post": [
4833+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4834+
],
4835+
"descriptions": [
4836+
"The string value was not expected to validate against the empty enumeration"
4837+
]
4838+
},
4839+
"exhaustive": {
4840+
"pre": [
4841+
[ "AssertionFail", "/enum", "#/enum", "" ]
4842+
],
4843+
"post": [
4844+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4845+
],
4846+
"descriptions": [
4847+
"The string value was not expected to validate against the empty enumeration"
4848+
]
4849+
}
4850+
},
4851+
{
4852+
"description": "empty_enum_integer",
4853+
"schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "enum": [] },
4854+
"instance": 42,
4855+
"valid": false,
4856+
"fast": {
4857+
"pre": [
4858+
[ "AssertionFail", "/enum", "#/enum", "" ]
4859+
],
4860+
"post": [
4861+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4862+
],
4863+
"descriptions": [
4864+
"The integer value was not expected to validate against the empty enumeration"
4865+
]
4866+
},
4867+
"exhaustive": {
4868+
"pre": [
4869+
[ "AssertionFail", "/enum", "#/enum", "" ]
4870+
],
4871+
"post": [
4872+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4873+
],
4874+
"descriptions": [
4875+
"The integer value was not expected to validate against the empty enumeration"
4876+
]
4877+
}
48224878
}
48234879
]

test/evaluator/evaluator_2020_12.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,5 +4338,61 @@
43384338
"The value was expected to be of type object"
43394339
]
43404340
}
4341+
},
4342+
{
4343+
"description": "empty_enum_string",
4344+
"schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "enum": [] },
4345+
"instance": "foo",
4346+
"valid": false,
4347+
"fast": {
4348+
"pre": [
4349+
[ "AssertionFail", "/enum", "#/enum", "" ]
4350+
],
4351+
"post": [
4352+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4353+
],
4354+
"descriptions": [
4355+
"The string value was not expected to validate against the empty enumeration"
4356+
]
4357+
},
4358+
"exhaustive": {
4359+
"pre": [
4360+
[ "AssertionFail", "/enum", "#/enum", "" ]
4361+
],
4362+
"post": [
4363+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4364+
],
4365+
"descriptions": [
4366+
"The string value was not expected to validate against the empty enumeration"
4367+
]
4368+
}
4369+
},
4370+
{
4371+
"description": "empty_enum_integer",
4372+
"schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "enum": [] },
4373+
"instance": 42,
4374+
"valid": false,
4375+
"fast": {
4376+
"pre": [
4377+
[ "AssertionFail", "/enum", "#/enum", "" ]
4378+
],
4379+
"post": [
4380+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4381+
],
4382+
"descriptions": [
4383+
"The integer value was not expected to validate against the empty enumeration"
4384+
]
4385+
},
4386+
"exhaustive": {
4387+
"pre": [
4388+
[ "AssertionFail", "/enum", "#/enum", "" ]
4389+
],
4390+
"post": [
4391+
[ false, "AssertionFail", "/enum", "#/enum", "" ]
4392+
],
4393+
"descriptions": [
4394+
"The integer value was not expected to validate against the empty enumeration"
4395+
]
4396+
}
43414397
}
43424398
]

0 commit comments

Comments
 (0)