Skip to content

Relative URL paths as $refs #80

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
jsignell opened this issue Sep 11, 2023 · 5 comments
Closed

Relative URL paths as $refs #80

jsignell opened this issue Sep 11, 2023 · 5 comments

Comments

@jsignell
Copy link

I am trying to replace RefResolver with Registry in pystac (stac-utils/pystac#1215) and cannot get relative paths to work. I wrote a retrieve function that should make the relative schema URIs absolute with respect to the location of the base schema, but it seems like the ../.. are getting stripped off.

Here is an example of the type of schemas I am working with: https://raw.githubusercontent.com/radiantearth/stac-spec/v0.8.1/collection-spec/json-schema/collection.json.

"../../catalog-spec/json-schema/catalog.json" for instance is just "catalog-spec/json-schema/catalog.json" within my retrieve function.

This is potentially similar to #70, but these refs are not prefixed by file so I think this style of ref is supposed to be legit

@Julian
Copy link
Member

Julian commented Sep 11, 2023

I (obviously in a minute or two) haven't looked completely carefully, but initially, those indeed don't look legit for similar reasons! It's ambiguous what you mean when writing that, whether it's relative to the path of the file itself or whether (the more likely case) that it's relative to the working directory of the process!

You likely should change to use some URI scheme with proper relative path support, but I'd have to take a closer look to be sure.

@jsignell
Copy link
Author

Thank you for your response! These are intended to be relative to the path of the file. I was hoping to make that behavior explicit within the retrieve function but the input is stripped. Is there a recommendation for how to work with relative refs?

@jsignell
Copy link
Author

As a follow-up: is the issue that the $id is not a URL? If so then this might only be an issue with older versions of the spec since later versions specify the $id as a real URL: https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json

@Julian
Copy link
Member

Julian commented Sep 11, 2023

As a follow-up: is the issue that the $id is not a URL?

I have to remind myself what the spec says honestly, what's going on here has to do with establishing a base URL basically -- and referencing has no way of knowing what base URL you mean (even though you obviously have one in mind, a base URL of the file path to the file you're using). My recollection is that yeah the JSON Schema says $id of the root document is supposed to be an absolute URI, but I forget and have to remind myself, it's been a bit since I wrote referencing even :D

Is there a recommendation for how to work with relative refs?

If I recall correctly from the other issue, the "hacky" way to proceed down this path regardless of whether it's allowed is, in retrieve, to ignore that you get an absolute path and regardless join it to your schema directory path. But I have to check again to see if there's an even better recommendation, or better something consistent with the spec.

And of course I could entirely be misremembering, so I'll leave this open anyhow to see if I've led you astray.

@jsignell
Copy link
Author

Ok it looks like just fixing up the $id so that it is a url did the trick! After I did that the rel refs worked just fine!

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