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

WIP: [CLI] Add new option -r to resolve local file references #680

Closed

Conversation

RomainTT
Copy link
Contributor

When the CLI is used, the local path to the schema is known. Therefore, if some other files are referenced with the ref key, the program knows where to search for them.

In the documentation of json-schema, it is stated:

$ref can also be a relative or absolute URI, so if you prefer to include your definitions in separate files, you can also do that. For example:

{ "$ref": "definitions.json#/address" }
would load the address schema from another file residing alongside this one.

And:

The $id property is a URI that serves two purposes:

It declares a unique identifier for the schema.
It declares a base URI against which $ref URIs are resolved.
[…]

But be aware of the second purpose of the $id property: that it declares a base URL for relative $ref URLs elsewhere in the file. For example, if you had:

{ "$ref": "person.json" }
in the same file, a JSON schema validation library that supported network fetching would fetch person.json from http://foo.bar/schemas/person.json, even if address.json was loaded from somewhere else, such as the local filesystem.

I think that feature can be supported by the command line. I therefore added the -r option.

@RomainTT
Copy link
Contributor Author

The main issue I have is that I don’t know how to make tests about that. My understanding of the current CLI tests is that there is no actual file at all, only fake openings. In that case, how to test this feature ? Maybe by redefining some of the os methods ?

@Julian
Copy link
Member

Julian commented Apr 18, 2020

Hi! Sorry, haven't gotten a chance to look at this yet but thanks again for the PR! Really appreciated.

Will try to give some guidance on how to test this (I suspect before digging to hard that an easy way to test it may be to rely on the metaschema files that are already shipped in the repo, and using those as the one you reference via relative references)

Also, on the option itself, I think my first reaction is I'd rather call this something like --base-uri? (Similar to what's in #669 which is about this essentially). What's being specified is a base URL that's used to resolve relative references, yeah?

@Julian Julian marked this pull request as draft April 18, 2020 16:59
@RomainTT
Copy link
Contributor Author

wow I totally forgot that PR, sorry. I’ll try to continue it soon.

@Julian Julian closed this Sep 20, 2020
@RomainTT RomainTT deleted the cli-local-file-ref branch September 22, 2021 09:06
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

Successfully merging this pull request may close these issues.

2 participants