skohub-io / skohub-editor

Apache License 2.0
5 stars 4 forks source link

Relative path $ref schemas should get base URL from parent schema #63

Open acka47 opened 3 years ago

acka47 commented 3 years ago

From @stefandesu in https://github.com/skohub-io/skohub-editor/issues/39#issuecomment-735725919:

I have an issue that seems to be related to this one. Our JSON Schemas for JSKOS are split up and reference each other. However, we are using relative URLs instead of absolute. For example, https://gbv.github.io/jskos/scheme.schema.json references several other schemas, like resource.schema.json. In SkoHub Editor, these don't get resolved properly. It uses the URL where the editor is hosted as the base URL instead of the id.

In the JSON Schema documentation, it says:

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

  • It declares a unique identifier for the schema.
  • It declares a base URI against which $ref URI-references are resolved.

So as far as I understand, if I reference resource.schema.json in a schema with the ID https://gbv.github.io/jskos/scheme.schema.json, it should be resolved as https://gbv.github.io/jskos/resource.schema.json.

The lookup mechanism for ref in SkoHub Editor should thus be adjusted so that the base URL is taken from the $id parent schema where $ref occurs.

stefandesu commented 3 years ago

I'm pretty sure this has to be implemented in the json-schema-ref-parser library since all you're doing is to use their dereference method. I couldn't find anything in their documentation or issues regarding this though.