diff --git a/src/jsonschema/default_compiler_draft4.h b/src/jsonschema/default_compiler_draft4.h index 959515e8f..f5581ed22 100644 --- a/src/jsonschema/default_compiler_draft4.h +++ b/src/jsonschema/default_compiler_draft4.h @@ -84,12 +84,13 @@ auto compiler_draft4_core_ref( if (!is_recursive && direct_children_references <= 5) { // TODO: Enable this optimization for 2019-09 on-wards - if (schema_context.vocabularies.contains( - "http://json-schema.org/draft-04/schema#") || - schema_context.vocabularies.contains( - "http://json-schema.org/draft-06/schema#") || - schema_context.vocabularies.contains( - "http://json-schema.org/draft-07/schema#")) { + if (context.mode == SchemaCompilerMode::FastValidation && + (schema_context.vocabularies.contains( + "http://json-schema.org/draft-04/schema#") || + schema_context.vocabularies.contains( + "http://json-schema.org/draft-06/schema#") || + schema_context.vocabularies.contains( + "http://json-schema.org/draft-07/schema#"))) { return compile(context, new_schema_context, dynamic_context, empty_pointer, empty_pointer, reference.destination); } else { diff --git a/src/jsonschema/default_compiler_draft7.h b/src/jsonschema/default_compiler_draft7.h index 1bfd6a661..2f60b1acf 100644 --- a/src/jsonschema/default_compiler_draft7.h +++ b/src/jsonschema/default_compiler_draft7.h @@ -66,6 +66,8 @@ auto compiler_draft7_applicator_if( } // We handle `then` as part of `if` +// TODO: Stop collapsing this keyword on exhaustive mode for debuggability +// purposes auto compiler_draft7_applicator_then(const SchemaCompilerContext &, const SchemaCompilerSchemaContext &, const SchemaCompilerDynamicContext &) @@ -74,6 +76,8 @@ auto compiler_draft7_applicator_then(const SchemaCompilerContext &, } // We handle `else` as part of `if` +// TODO: Stop collapsing this keyword on exhaustive mode for debuggability +// purposes auto compiler_draft7_applicator_else(const SchemaCompilerContext &, const SchemaCompilerSchemaContext &, const SchemaCompilerDynamicContext &) diff --git a/test/evaluator/evaluator_draft4_test.cc b/test/evaluator/evaluator_draft4_test.cc index 4da2d9e8e..90a7d5293 100644 --- a/test/evaluator/evaluator_draft4_test.cc +++ b/test/evaluator/evaluator_draft4_test.cc @@ -378,6 +378,41 @@ TEST(JSONSchema_evaluator_draft4, ref_2) { "The string value was expected to validate against the given subschema"); } +TEST(JSONSchema_evaluator_draft4, ref_2_exhaustive) { + const sourcemeta::jsontoolkit::JSON schema{ + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-04/schema#", + "allOf": [ { "$ref": "#/definitions/string" } ], + "definitions": { + "string": { "type": "string" } + } + })JSON")}; + + const sourcemeta::jsontoolkit::JSON instance{"foo"}; + + EVALUATE_WITH_TRACE_EXHAUSTIVE_SUCCESS(schema, instance, 3); + + EVALUATE_TRACE_PRE(0, LogicalAnd, "/allOf", "#/allOf", ""); + EVALUATE_TRACE_PRE(1, LogicalAnd, "/allOf/0/$ref", "#/allOf/0/$ref", ""); + EVALUATE_TRACE_PRE(2, AssertionTypeStrict, "/allOf/0/$ref/type", + "#/definitions/string/type", ""); + + EVALUATE_TRACE_POST_SUCCESS(0, AssertionTypeStrict, "/allOf/0/$ref/type", + "#/definitions/string/type", ""); + EVALUATE_TRACE_POST_SUCCESS(1, LogicalAnd, "/allOf/0/$ref", "#/allOf/0/$ref", + ""); + EVALUATE_TRACE_POST_SUCCESS(2, LogicalAnd, "/allOf", "#/allOf", ""); + + EVALUATE_TRACE_POST_DESCRIBE(instance, 0, + "The value was expected to be of type string"); + EVALUATE_TRACE_POST_DESCRIBE(instance, 1, + "The string value was expected to validate " + "against the statically referenced schema"); + EVALUATE_TRACE_POST_DESCRIBE( + instance, 2, + "The string value was expected to validate against the given subschema"); +} + TEST(JSONSchema_evaluator_draft4, ref_3) { const sourcemeta::jsontoolkit::JSON schema{ sourcemeta::jsontoolkit::parse(R"JSON({