Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative base URIs #125

Merged
merged 1 commit into from
Nov 4, 2024
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
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa caad2e1ceedf9fd1a18686a6a6d1e2b9757ead75
jsontoolkit https://github.com/sourcemeta/jsontoolkit 3b644bfb012c506b4e5f749f26e789d38bff1254
jsontoolkit https://github.com/sourcemeta/jsontoolkit c6d056cc608bf98705ad7700c8c891e1cf6865a0
googletest https://github.com/google/googletest a7f443b80b105f940225332ed3c31f2790092f47
googlebenchmark https://github.com/google/benchmark 378fe693a1ef51500db21b11ff05a8018c5f0e55
jsonschema-test-suite https://github.com/json-schema-org/JSON-Schema-Test-Suite c2badb1298a8698f86dadf1aea7b44b3a894e5ac
2 changes: 1 addition & 1 deletion src/compiler/compile_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ inline auto find_adjacent(const Context &context,
sourcemeta::jsontoolkit::to_uri(
sourcemeta::jsontoolkit::to_pointer(reference.fragment.value_or(""))
.concat({keyword}))
.resolve_from_if_absolute(reference.base.value_or(""))};
.try_resolve_from(reference.base.value_or(""))};

// TODO: When this logic is used by
// `unevaluatedProperties`/`unevaluatedItems`, how can we let the
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/default_compiler_2020_12.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ auto compiler_2020_12_core_dynamicref(const Context &context,
assert(schema_context.schema.at(dynamic_context.keyword).is_string());
sourcemeta::jsontoolkit::URI reference{
schema_context.schema.at(dynamic_context.keyword).to_string()};
reference.resolve_from_if_absolute(schema_context.base);
reference.try_resolve_from(schema_context.base);
reference.canonicalize();
// We handle the non-anchor variant by not treating it as a dynamic reference
assert(reference.fragment().has_value());
Expand Down
32 changes: 32 additions & 0 deletions test/evaluator/evaluator_draft4_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5658,3 +5658,35 @@ TEST(Evaluator_draft4, ref_to_non_schema) {
FAIL();
}
}

TEST(Evaluator_draft4, relative_base_uri_with_ref) {
const sourcemeta::jsontoolkit::JSON schema{
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "http://json-schema.org/draft-04/schema",
"id": "common",
"allOf": [ { "$ref": "#reference" } ],
"definitions": {
"reference": {
"id": "#reference",
"type": "string"
}
}
})JSON")};

const sourcemeta::jsontoolkit::JSON instance{"test"};
EVALUATE_WITH_TRACE_FAST_SUCCESS(schema, instance, 2);

EVALUATE_TRACE_PRE(0, LogicalAnd, "/allOf", "common#/allOf", "");
EVALUATE_TRACE_PRE(1, AssertionTypeStrict, "/allOf/0/$ref/type",
"common#/definitions/reference/type", "");

EVALUATE_TRACE_POST_SUCCESS(0, AssertionTypeStrict, "/allOf/0/$ref/type",
"common#/definitions/reference/type", "");
EVALUATE_TRACE_POST_SUCCESS(1, LogicalAnd, "/allOf", "common#/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 given subschema");
}
2 changes: 1 addition & 1 deletion vendor/jsontoolkit/src/jsonpointer/jsonpointer.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/jsontoolkit/src/jsonschema/reference.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions vendor/jsontoolkit/src/uri/uri.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading