eclipsesource/play-json-schema-validator

ref to local file

Closed this issue · 8 comments

how to refer to schema in another local file ?

I have tried
"user": {"$ref": "file:///full/path/schema.json#/definitions/user"}
"user": {"$ref": "file:full/path/schema.json#/definitions/user"}
"user": {"$ref": "/full/path/schema.json#/definitions/user"}

in all of the cases I am getting "Could not resolve ref..."

*** is it possible to use relative path ?

Thanks

Hi,
it is possible to use relative paths (which will be resolved against the base URL that you can alter with the id property, more info regarding resolution of refs can be found here). You might also want to look at talk.json which uses relative refs and the respective test cases here and here.
Let me know if this answers your question, thanks.

Hi,

this is still not working for me.
I am unable to refer to local file (even using full path).
still getting Could not resolve ref error msg.

** update:
I was able to resolve the issues after reading
http://spacetelescope.github.io/understanding-json-schema/structuring.html#reuse blog
for the 5th time :-), using the id property.

my question now is, if I am using local file system,
is the id in the file where I have the refer, must include full path ?
can I make the id somehow dynamic (for example reading from ENV var) ?

Thanks,

This is currently not possible , but I'm still wondering why relative refs won't work for you. Could you upload your files somewhere (e.g. as a gist) and tell me exactly what you are trying to achieve, such that I am able to either give you a code example or spot an error.
Thanks

actually, after that I eventually understood how to use the "id" correctly, the relative path is also working.

Thanks for the help.

Glad you were able to get it working. I'm closing this issue for now, if there's anything else let me know.

@edgarmueller when you said "This is currently not possible" were you saying that it's not possible to have relative $ref resolution for files that are only on the local file system?

Do I need files accessible at an actual routable URL to use relative $ref?

I'm using Play and I put my schemas into conf/schemas. I have orderAddress.json in there, then I also have orderAddresses.json next to it in the same folder with the following:

{
  "type": "array",
  "items": {
    "$ref": "orderAddress.json"
  }
}

Then I get the error "Could not resolve ref orderAddress.json". Any pointers would be appreciated! Thanks

False alarm. I figured it out. Makes sense you have to use a URI even locally. The problem was that I was parsing the schema from a stream so there's no context as to where it is.

@wuservices Glad to hear. Guess it would probably make sense to mention that in the docs somewhere then.