Skip to content

Schema id does not declare a base URL for relative $ref URLs #26

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

Closed
xaviarias opened this issue Apr 4, 2017 · 5 comments
Closed

Schema id does not declare a base URL for relative $ref URLs #26

xaviarias opened this issue Apr 4, 2017 · 5 comments

Comments

@xaviarias
Copy link

When resolving relative $references, URLs are constructed using the reference value directly without using the base URL of the referencing schema.

https://spacetelescope.github.io/understanding-json-schema/structuring.html?highlight=dependencies#the-id-property

For example, if you own the foo.bar domain, and you had a schema for addresses, you may set its id as follows:

"id": "http://foo.bar/schemas/address.json"

This provides a unique identifier for the schema, as well as, in most cases, indicating where it may be downloaded. For example: { "$ref": "person.json" }

A JSON schema validation library would fetch person.json from http://foo.bar/schemas/person.json, even if address.json was loaded from the local filesystem.

@eskabetxe
Copy link
Contributor

i was this issue too..
@stevehu i will check this..

@eskabetxe
Copy link
Contributor

created PR
#37

it could be better, if we can had some level of cache for the url/content, it would not be necessary to be downloading the content to each $ref as it always made "new RefValidator"

@stevehu
Copy link
Contributor

stevehu commented Jun 26, 2017

@eskabetxe I think it is cached as we only parse schema in the factory once. And all the validators are created during parsing and cached in a map. I didn't look at the code but make the comment based on the way it was implemented. If you could confirm that we parse the ref on a per request basis, then we definitely need to get it fixed. Could you please confirm? Thanks.

@eskabetxe
Copy link
Contributor

for this example
{ "$schema": "http://json-schema.org/draft-04/schema#", "id": "http://localhost:8080/testing.json", "properties": { "prop1": { "$ref": "rules.json#/prop1" }, "prop2": { "$ref": "rules.json#/prop2" }, "prop3": { "$ref": "rules.json#/prop3" } } }

the $ref file (rules.json) will be charge 3 times..
because for each prop we create a new RefValidator that will download rules.json and check the proper rule

i think that prop1, prop2, etc are cached, but the file rules.json is download 3 times and this could be improved

@stevehu
Copy link
Contributor

stevehu commented Jun 7, 2019

This issue should be resolved by #141

@stevehu stevehu closed this as completed Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants