Skip to content
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

$ref fails with the file: URI scheme #113

Open
ricky-rockstar opened this issue Aug 24, 2022 · 2 comments
Open

$ref fails with the file: URI scheme #113

ricky-rockstar opened this issue Aug 24, 2022 · 2 comments

Comments

@ricky-rockstar
Copy link

ricky-rockstar commented Aug 24, 2022

XMLspy successfully validates JSON schema A containing the following valid file URI reference to schema B on the local C drive :

"$ref": "file:///C:/Git/Test/schemaValidate/user/schemaB.json#"

ie. as long as schemaB.json exists at the local location and is a valid json schema, schema A validates successfully.

In opis schema A does not validate.

I can set up an external opis workaround by using:

$validator->resolver()->registerPrefix("http://rubbish.com/","C:\\Git\\Test\\schemaValidate");

and then replacing the above $ref with the following:

"$ref": "http://rubbish.com/user/schemaB.json#"

However this approach is problematic for the following reasons:

  1. instead of the $ref relationship being self defining in its own right within the schema, I have to set up an external "meaningless" domain relationship just to access a relative schema on the local server.
  2. I have no need to access schemas via web domains so http is meaningless for my use case.
  3. The external resolver() mapping requirement means the schema is not self defining and so external applications such as XMLspy cannot use or validate the schema as http://rubbish.com/user/schemaB.json is only meaningful to opis.

Am I doing something wrong? ie. is there a way to make schema A reference local schema B via "$ref": "file:///......" without any requirement for an external mapping or is this a very very welcome piece of functionality that could be added?

(and even better would be the ability to use a "relative inter-schema $ref" eg file://./some/dir/schemaB.json rather than absolute - not sure if this is possible?)

Thanks so much!

@handrews
Copy link

@ricky-rockstar the JSON Schema specification recommends against automatically retrieving references by default. Implementations that do offer automatic retrieval (whether by default or otherwise) are not required to automatically support any particular set of URI schemes/protocols.

I'm not familiar enough with how Opis is implemented to offer advice on how it works now, but I'd expect that you'd need to set up a resolver for file:// URIs that would do the necessary filesystem I/O. In my experience, you rarely actually want to use file:// in $id or $ref. It's much more common to use https:// (or even urn: or tag: if you don't want to imply network access) in $id or $ref and then configure a resolver that loads those schemas from the filesystem.

$id is intended to be an identifier, not a locator- so having an https:// or urn: identifier regardless of how the schema is located (in your case, from the filesystem) is pretty common.

@handrews
Copy link

See also #89.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants