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

Dereferencing schemas without file extensions #76

Closed
anandsunderraman opened this issue Mar 12, 2018 · 2 comments
Closed

Dereferencing schemas without file extensions #76

anandsunderraman opened this issue Mar 12, 2018 · 2 comments

Comments

@anandsunderraman
Copy link

anandsunderraman commented Mar 12, 2018

Hi

This is not an issue but more about how to use the library.
My question is similar to #22

I am trying to parse a RAML file

here when a schema is referencing another schema using $ref it so happens that the externally referenced file extension is not provided. Example

//email.schema
{
  "$schema": "http:https://json-schema.org/draft-04/schema#",
  "definitions": {
    "email": {
      "id": "email",
      "type": "string",
      "format": "email"
    }
}

//user.schema
{
  "$schema": "http:https://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "email": {
      "$ref": "email"
    }
  }
}

While using the library it is not able to locate the schema file for email because it needs to search by extension.

Currently I am getting around that by passing a custom canRead function to file dereferencing option. The custom canRead function appends .schema to the file.url property
However I was wondering if there was a better way to achieve it.

@JamesMessinger
Copy link
Member

JSON Schema $Ref Parser expects the $ref to be a valid relative URI (per the spec), so it should be the full file name, including the extension (i.e. "$ref": "email.schema").

That said, if you specifically don't want to include the file extension due to compatibility with other tooling, then your canRead workaround is probably the best option. You're essentially overriding the default resolution algorithm to resolve to a different file path, which is a valid use-case.

@anandsunderraman
Copy link
Author

thanks for your prompt response, makes sense

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