Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/compiler/default_compiler_draft4.h
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,11 @@ auto compiler_draft4_validation_enum(const Context &context,
return {};
}

if (schema_context.schema.at(dynamic_context.keyword).empty()) {
return {make(sourcemeta::blaze::InstructionIndex::AssertionFail, context,
schema_context, dynamic_context, ValueNone{})};
}

if (schema_context.schema.at(dynamic_context.keyword).size() == 1) {
return {
make(sourcemeta::blaze::InstructionIndex::AssertionEqual, context,
Expand Down
8 changes: 8 additions & 0 deletions src/evaluator/evaluator_describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ auto describe(const bool valid, const Instruction &step,
const sourcemeta::core::JSON &target{get(instance, instance_location)};

if (step.type == sourcemeta::blaze::InstructionIndex::AssertionFail) {
if (keyword == "enum") {
std::ostringstream message;
message << "The " << type_name(target.type())
<< " value was not expected to validate against the empty "
"enumeration";
return message.str();
}

if (keyword == "contains") {
return "The constraints declared for this keyword were not satisfiable";
}
Expand Down
56 changes: 56 additions & 0 deletions test/evaluator/evaluator_2019_09.json
Original file line number Diff line number Diff line change
Expand Up @@ -4819,5 +4819,61 @@
"The object value was not expected to define unevaluated properties"
]
}
},
{
"description": "empty_enum_string",
"schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "enum": [] },
"instance": "foo",
"valid": false,
"fast": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The string value was not expected to validate against the empty enumeration"
]
},
"exhaustive": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The string value was not expected to validate against the empty enumeration"
]
}
},
{
"description": "empty_enum_integer",
"schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", "enum": [] },
"instance": 42,
"valid": false,
"fast": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The integer value was not expected to validate against the empty enumeration"
]
},
"exhaustive": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The integer value was not expected to validate against the empty enumeration"
]
}
}
]
56 changes: 56 additions & 0 deletions test/evaluator/evaluator_2020_12.json
Original file line number Diff line number Diff line change
Expand Up @@ -4338,5 +4338,61 @@
"The value was expected to be of type object"
]
}
},
{
"description": "empty_enum_string",
"schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "enum": [] },
"instance": "foo",
"valid": false,
"fast": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The string value was not expected to validate against the empty enumeration"
]
},
"exhaustive": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The string value was not expected to validate against the empty enumeration"
]
}
},
{
"description": "empty_enum_integer",
"schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "enum": [] },
"instance": 42,
"valid": false,
"fast": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The integer value was not expected to validate against the empty enumeration"
]
},
"exhaustive": {
"pre": [
[ "AssertionFail", "/enum", "#/enum", "" ]
],
"post": [
[ false, "AssertionFail", "/enum", "#/enum", "" ]
],
"descriptions": [
"The integer value was not expected to validate against the empty enumeration"
]
}
}
]
Loading