Problem with $ref in 3.0.1 ?

40 views
Skip to first unread message

Gabriel Georges

unread,
May 20, 2019, 7:04:30 AM5/20/19
to jsonschema - An implementation of JSON Schema for Python
Hello,

I am encountering problems with the jsonschema 3.0.1 module. With the tests I have done, I came to the conclusion that a $ref inside a $ref is no more supported in 3.0.1 while it worked with the 2.6.0 version of the module.

I have detailed everything here (json examples and error message) : https://stackoverflow.com/questions/56182349/multi-stage-ref-doesnt-work-with-jsonschema-version-3-0-1

Can someone confirm me there is a problem here ?
Thanks,

Gabriel

Julian Berman

unread,
May 20, 2019, 8:03:07 AM5/20/19
to Gabriel Georges, jsonschema - An implementation of JSON Schema for Python
Hi. Happy to help, though would be a lot easier if you worked on creating a minimal example (and then posted that to the issue tracker if it indeed does different things on 2.6 as 3.0).

Thanks,
-J

--
You received this message because you are subscribed to the Google Groups "jsonschema - An implementation of JSON Schema for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema+...@googlegroups.com.
To post to this group, send email to jsons...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonschema/0229ad82-2e93-4612-84f8-7ddd515d5fc2%40googlegroups.com.

Gabriel Georges

unread,
May 20, 2019, 8:32:34 AM5/20/19
to jsonschema - An implementation of JSON Schema for Python
Hi Julian,

Indeed taking a new look at my post, some simplifications can be made. I hope the linked files are better.
I'm going to correct the Stackoverflow post too, thank you.



Le lundi 20 mai 2019 14:03:07 UTC+2, Julian Berman a écrit :
Hi. Happy to help, though would be a lot easier if you worked on creating a minimal example (and then posted that to the issue tracker if it indeed does different things on 2.6 as 3.0).

Thanks,
-J

On Mon, May 20, 2019 at 7:04 AM Gabriel Georges <georges...@gmail.com> wrote:
Hello,

I am encountering problems with the jsonschema 3.0.1 module. With the tests I have done, I came to the conclusion that a $ref inside a $ref is no more supported in 3.0.1 while it worked with the 2.6.0 version of the module.

I have detailed everything here (json examples and error message) : https://stackoverflow.com/questions/56182349/multi-stage-ref-doesnt-work-with-jsonschema-version-3-0-1

Can someone confirm me there is a problem here ?
Thanks,

Gabriel

--
You received this message because you are subscribed to the Google Groups "jsonschema - An implementation of JSON Schema for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsons...@googlegroups.com.
usingRefs.schema.json
myjson.json
noRefs.schema.json

Yehuda Deutsch

unread,
May 20, 2019, 12:12:48 PM5/20/19
to Gabriel Georges, jsonschema - An implementation of JSON Schema for Python
TL;DR: install the "rfc3987" package, this will handle "uri-reference" format types ($ref is defined in draft-06 and draft-07 and was simply not defined in draft-04, so the validator handled it as is).

Using just jsonschema 3.0.1 I was able to reproduce both behaviors
  • jsonschema.validate(my_json, using_refs_schema, cls=jsonschema.Draft4Validator) - no errors
  • jsonschema.validate(my_json, using_refs_schema, cls=jsonschema.Draft7Validator) - KeyError
You should notice that draft-04 has no definition of $ref in the schema, though using it in the schema. draft-07 and draft-07 are defining "$ref" as a string with the format "uri-reference", this validation is handled with the rfc3987 package, installing this package resolved the issue.
I think the silent pass on failing to import some format handlers should be revisited.

Yehuda
------------------------------
Yehuda Deutsch | IT Developer


To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema+...@googlegroups.com.

To post to this group, send email to jsons...@googlegroups.com.

Yehuda Deutsch

unread,
May 20, 2019, 12:27:11 PM5/20/19
to Gabriel Georges, jsonschema - An implementation of JSON Schema for Python
In SO I pointed out to actually install "jsonschema[format]" and not specifically install "rfc3987".

Yehuda
------------------------------
Yehuda Deutsch | IT Developer

Yehuda Deutsch

unread,
May 21, 2019, 6:08:45 AM5/21/19
to Gabriel Georges, jsonschema - An implementation of JSON Schema for Python
As Gabriel pointed out in private, this Exception is not resolved using the format extras of jsonschema, the rfc3987 supported checks do not help.

TL;DR: You have two options:
  1. Remove the "$id" properties from the definitions
  2. Use "#/" in the "$id" properties

Details:
The issue is with the IDs, up until draft-04, "$ref" and "$id" were treated at face value, nothing special, but starting with draft-06 these are "uri-reference"s, in which case, when descending into '{"$id": "schemaTopProperty"}', resolving '{"$ref": "justAString"}' is no more looking for a fragment "justAString" at the root structure, but at "/justAString" under "schemaTopProperty" host, which is a remote reference.

Hence my solutions to either remove the "$id"s which cause the definitions to be URLs (hosts in fact), or to define the "$id"s as what they are, fragments in the current schema.

Yehuda
------------------------------
Yehuda Deutsch | IT Developer

Reply all
Reply to author
Forward
0 new messages