back again with another $ref question

57 views
Skip to first unread message

rlyacht

unread,
Apr 3, 2018, 6:11:17 PM4/3/18
to jsonschema - An implementation of JSON Schema for Python
This one will likely also be my error, but I just cant figure it out.

In a nutshell:  I am using $ref to refer to types defined in local files.  If I   structure the file as  I've seen in examples, using a "definitions" section, I get an exception from urlopen when I run jsonschema, that says the file is not found.  If I just put the definition of the type at the "top level", then the $ref works fine. Even putting in an absolute path (which I don't want to do anyway) doesn't fix my issue.

Here are some toy examples that illustrate my problem, starting with the one that works ok.  I appreciate anyone's having a look.

good.schema.json
{
   
"$schema": "http://json-schema.org/draft-04/schema#",

   
"properties" : {
       
"ablah" : {"$ref" : "file:blah-flat.json"}
   
}    
}




blah-flat.json
{
   
"type" : "string"
}


blah-example.json
{
   
"ablah" : "hi mom"
}


Result - no errors
> jsonschema -i blah-example.json  good.schema.json
>

So this works fine.  Here's where I have a problem.  I use a different file to define the type for "ablah":

blahdef.json
{
   
"definitions" : {
     
"Blah" : {
       
"type" : "string"
     
}
   
}
}


Then have the schema refer to it like this:

problem.schema.json
{
   
"$schema": "http://json-schema.org/draft-04/schema#",

   
"properties" : {
   
"ablah" : {"$ref" : "file:blahdef.json#/definitions/Blah"}
   
}    
}


and I get this error from jsonschema -i blah-example.json problem.schema.json:

jsonschema.exceptions.RefResolutionError: <urlopen error [Errno 2] No such file or directory: '/blahdef.json'>
>






rlyacht

unread,
Apr 4, 2018, 9:27:13 PM4/4/18
to jsonschema - An implementation of JSON Schema for Python
I found the answer  in this post. It explains how to set the resolver appropriately.
Reply all
Reply to author
Forward
0 new messages