-
-
Notifications
You must be signed in to change notification settings - Fork 217
Add tests for refs with relative uris #457
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
Conversation
I could not find a way to port this to older versions, as they seem not to allow definitions in nested schemas. Is there a way to write a test with multiple, separate schemas? |
5d07dbe
to
0eeed11
Compare
@amosonn take a look at the |
f435fc9
to
f883394
Compare
Added these tests, and also some for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the tests for $recursiveRef
and $dynamicRef
. $recursiveRef
doesn't support any value other than an empty fragment ("#"
), so that doesn't apply to what is being tested. $dynamicRef
does support non-fragment-only URIs, but how that works is a little complicated. I'll be writing tests for $dynamicRef
next week, and I'll make sure relative URI resolution is covered.
I've only skimmed this so far, but I'd be really surprised if relative URI resolution isn't covered somewhere already. I'll take a closer look later.
There are tests for relative uri resolution, I think, but not for relative uri resolution followed by |
7796a24
to
1b7a4d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked closer at the tests and they look fine except for some use of relative URIs for $id
s at the top level of schemas.
I'm not sure "ref.json" is the right place for these tests. All other tests regarding embedding schemas with $id
are in "refRemote.json". These should probably be there as well. I don't feel strongly about it tho if others disagree.
Summary:
Anything else? |
@@ -0,0 +1,11 @@ | |||
{ | |||
"$id": "http://localhost:1234/ref-and-defs.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we talked about $id
s being required to be absolute URIs, I said,
Same goes for the $ids in the "remotes" schemas.
It occurred to me that that's not true. The "remotes" are designed as if they are fetched from http://localhost:1234/{path-to-schema}
. Therefore, they have a retrieval URI and don't need an absolute URI. That's why none of them have $id
and that's not a problem. So, $id
s (or even relative $id
s) are fine in the "remotes" schemas, but they aren't necessary. I'm ok with leaving them in (even tho they are redundant) or taking them out.
Both for absolute and relative refs.
The "Test Suite Sanity Checking" build failure appears to be wrong. I think this is safe to merge. |
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
Previously, this was always evalutating pointers using the root schema. We actually want to evaluate them using the nearest parent schema with an `$id`, which we look up here using `parent_uri`. Addresses failures from: json-schema-org/JSON-Schema-Test-Suite#457
This is an attempt to simplify dereferencing refs and address issues exposed by new json-schema-test-suite tests. The main thing here is giving schema objects a `base_uri` that's used when resolving ids (and as the initial base URI for instances). Child schemas use the `ref_uri` that was used to resolve them as their `base_uri` in order to get nested refs and ids to resolve properly. More details about specific issues: - `$id` is ignored when `$ref` is present (`instance.base_uri` is updated after `validate_ref`), because `$ref` isn't supposed to take sibling `$id` values into account. `@base_uri` handles nested refs. Exposed by: json-schema-org/JSON-Schema-Test-Suite#493 - JSON pointers are evaluated relative to the ref URI. Previously, pointers were always evaluated using the root schema. Now they're evaluated relative to the schema with a matching `$id` (usually nearest parent with an `$id`; or specific id (see below); default is root). Exposed by: json-schema-org/JSON-Schema-Test-Suite#457 - JSON pointers are evaluated for id refs. This allows a ref to look up a schema by `$id` and then apply a JSON pointer to use a subschema. This uses the same logic as above. The important part is removing the fragment from `ref_uri` if it's a JSON pointer so that the lookup in `ids` works properly. The fragment is kept if it's not a JSON pointer to support location-independent ids. Exposed by: json-schema-org/JSON-Schema-Test-Suite#578 - JSON pointer refs are always joined with the base URI. I [started handling them][0] separately because of an [issue][1] with invalid URIs. But now I think that was incorrect and that fragment pointers need to be encoded properly for URIs. The [specification says][2]: > In all cases, dereferencing a "$ref" reference involves first > resolving its value as a URI reference against the current base URI. - Empty fragments are removed in `join_uri` to have consistent URIs to lookup in `ids`. Meta schemas, for example, have empty fragments in their top-level ids (eg, `http://json-schema.org/draft-07/schema#`) and removing the JSON pointer fragments causes them not to be found. [0]: b91115e [1]: #54 [2]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3.2
This is an attempt to simplify dereferencing refs and address issues exposed by new json-schema-test-suite tests. The main thing here is giving schema objects a `base_uri` that's used when resolving ids (and as the initial base URI for instances). Child schemas use the `ref_uri` that was used to resolve them as their `base_uri` in order to get nested refs and ids to resolve properly. More details about specific issues: - `$id` is ignored when `$ref` is present (`instance.base_uri` is updated after `validate_ref`), because `$ref` isn't supposed to take sibling `$id` values into account. `@base_uri` handles nested refs. Exposed by: json-schema-org/JSON-Schema-Test-Suite#493 - JSON pointers are evaluated relative to the ref URI. Previously, pointers were always evaluated using the root schema. Now they're evaluated relative to the schema with a matching `$id` (usually nearest parent with an `$id`; or specific id (see below); default is root). Exposed by: json-schema-org/JSON-Schema-Test-Suite#457 - JSON pointers are evaluated for id refs. This allows a ref to look up a schema by `$id` and then apply a JSON pointer to use a subschema. This uses the same logic as above. The important part is removing the fragment from `ref_uri` if it's a JSON pointer so that the lookup in `ids` works properly. The fragment is kept if it's not a JSON pointer to support location-independent ids. Exposed by: json-schema-org/JSON-Schema-Test-Suite#578 - JSON pointer refs are always joined with the base URI. I [started handling them][0] separately because of an [issue][1] with invalid URIs. But now I think that was incorrect and that fragment pointers need to be encoded properly for URIs. The [specification says][2]: > In all cases, dereferencing a "$ref" reference involves first > resolving its value as a URI reference against the current base URI. - Empty fragments are removed in `join_uri` to have consistent URIs to lookup in `ids`. Meta schemas, for example, have empty fragments in their top-level ids (eg, `http://json-schema.org/draft-07/schema#`) and removing the JSON pointer fragments causes them not to be found. [0]: b91115e [1]: #54 [2]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3.2
This is an attempt to simplify dereferencing refs and address issues exposed by new json-schema-test-suite tests. The main thing here is giving schema objects a `base_uri` that's used when resolving ids (and as the initial base URI for instances). Child schemas use the `ref_uri` that was used to resolve them as their `base_uri` in order to get nested refs and ids to resolve properly. More details about specific issues: - `$id` is ignored when `$ref` is present (`instance.base_uri` is updated after `validate_ref`), because `$ref` isn't supposed to take sibling `$id` values into account. `@base_uri` handles nested refs. Exposed by: json-schema-org/JSON-Schema-Test-Suite#493 - JSON pointers are evaluated relative to the ref URI. Previously, pointers were always evaluated using the root schema. Now they're evaluated relative to the schema with a matching `$id` (usually nearest parent with an `$id`; or specific id (see below); default is root). Exposed by: json-schema-org/JSON-Schema-Test-Suite#457 - JSON pointers are evaluated for id refs. This allows a ref to look up a schema by `$id` and then apply a JSON pointer to use a subschema. This uses the same logic as above. The important part is removing the fragment from `ref_uri` if it's a JSON pointer so that the lookup in `ids` works properly. The fragment is kept if it's not a JSON pointer to support location-independent ids. Exposed by: json-schema-org/JSON-Schema-Test-Suite#578 - JSON pointer refs are always joined with the base URI. I [started handling them][0] separately because of an [issue][1] with invalid URIs. But now I think that was incorrect and that fragment pointers need to be encoded properly for URIs. The [specification says][2]: > In all cases, dereferencing a "$ref" reference involves first > resolving its value as a URI reference against the current base URI. - Empty fragments are removed in `join_uri` to have consistent URIs to lookup in `ids`. Meta schemas, for example, have empty fragments in their top-level ids (eg, `http://json-schema.org/draft-07/schema#`) and removing the JSON pointer fragments causes them not to be found. [0]: b91115e [1]: #54 [2]: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8.3.2
No description provided.