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

Using dereference with base url throws errors. #130

Closed
telion2 opened this issue Jul 2, 2019 · 1 comment
Closed

Using dereference with base url throws errors. #130

telion2 opened this issue Jul 2, 2019 · 1 comment

Comments

@telion2
Copy link

telion2 commented Jul 2, 2019

Hello,
My Schemas look like this:
Schema1:

{    //Schema stuff...
    "$ref": "./meta_nlp_schema.json#meta"
    ...
}

Schema2: (meta)

{...
      "$id": "/meta",
     ...
}

Say I use dereference without base url would lead to this error:
Error parsingSyntaxError: Invalid $ref pointer "meta". Pointers must begin with "#/"
Which is not a very helpful Error message, since belive my $ref to be correct following this guide:
https://swagger.io/docs/specification/using-ref/
Also mentioned in #42
I also tested it with these, which either threw a path error or just wrote the ref element without inserting the content:

 "$ref": "#/meta_nlp_schema.json#meta"
 "$ref": "#./meta_nlp_schema.json#meta"
 "$ref": "#meta_nlp_schema.json#meta"
 "$ref": "meta_nlp_schema.json#meta"
 "$ref": "#meta"
 "$ref": "#/meta"

Say I use a dereference with a base url (following #20):
jsonschema = await parser.dereference('./json_schemes/','./json_schemes/standard_message_schema.json', {});
Would lead to this Error:

 Error: Error opening file "C:\Medieninformaitk\Medieninformatik\BA\Code\ConChat\json_schemes\"
EISDIR: illegal operation on a directory, read
    at fs.readFile (C:\Medieninformaitk\Medieninformatik\BA\Code\ConChat\node_modules\json-schema-ref-parser\lib\resolvers\file.js:51:20)
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:37:12)

If I understand this error correctly, then $RefParser trys to read a folder, which of course doesnt work. But that is not the behavior I expected. I expected the Parser to resolve refs like above, relative to the folder I give as a base url.

Or to generalize my problem:
I want to parse a folder full of json schemas so I can validate them against a json object in js.
Can I do that here?
(Coming from https://stackoverflow.com/questions/56851739/how-to-load-a-json-folder-into-javascript )

@JamesMessinger
Copy link
Member

The error message you're getting:

Invalid $ref pointer "meta". Pointers must begin with "#/"

is caused by the missing / character in the JSON reference path.

"$ref": "./meta_nlp_schema.json#meta"

Add the missing / character after the # to resolve the error:

"$ref": "./meta_nlp_schema.json#/meta"

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

No branches or pull requests

2 participants