-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Error resolving $refs to files in same directory #93
Comments
I'm unable to reproduce this issue. Here's my attempt to reproduce it: https://runkit.com/bigstickcarpet/json-schema-ref-parser-issue-93 Notice the error message at the bottom. The path to |
I noticed that your original code was using a Windows path, so I also ran this test on a Windows machine, to make sure it wasn't a Windows-specific bug. However, it worked correctly on Windows too. |
I've verified this on two different (windows) machines now. I suppose that means I am using the library incorrectly. After stepping through more of the code I think I have narrowed down the exact scenario. Despite the error message, I actually believe it is this ref that is causing the problem. The only thing unique about my setup is that this is all running within a VSCode extension. If I have time later I'll see if I can recreate this issues as a unit test against this project. Edit: Just saw your test to try and reproduce, I think you need to add a ref similar to what I have linked above in this comment inside of |
Cool! I look forward to trying out your VSCode extension! I cloned your repo locally on a Windows machine, then created a const refParser = require('json-schema-ref-parser')
refParser.bundle('petstore.yaml', (err, schema) => {
if (err) {
console.error('ERROR:', err);
}
else {
console.log('SUCCESS:', schema);
}
}); Then I ran the script like this: cd test\resources\v2.0\yaml
node bug_reproduction.js And it worked correctly. Can you please try the same script on your machine and see if it works. If you get an error, then perhaps there's something unique about your environment which is causing the problem. Perhaps some issue with file or folder permissions, or something? |
Oh wait! I may have just reproduced the error... or at least a similar error that may be related to yours. In the example above, the script file ( const refParser = require('json-schema-ref-parser');
const path = require('path');
let absolutePath = path.join(__dirname, 'petstore.yaml');
refParser.bundle(absolutePath, (err, schema) => {
if (err) {
console.error('ERROR:', err);
}
else {
console.log('SUCCESS:', schema);
}
}); And I ran the script from a different directory: cd \
node bug_reproduction.js And I got this error, which is similar to the one you got:
After a bit of debugging, I discovered that the error is caused by the I will release a patch for this bug momentarily. Hopefully it fixes your issue. Please let me know either way. |
Just released the patched version ( |
First of all, thank you for taking some extra time to investigate further. I installed the patch and copied your test and tried running via the command line (to avoid any potential vscode abnormalities) and I had the exact same error as before. I'm not sure why you don't get the same error as me but I have been able to solve my issue. I believe this boils down to me incorrectly using json refs/pointers in the schema. In the child schema get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limits
in: query
description: How many items to return at one time (max 100)
required: false
type: integer
format: int32
responses:
"200":
description: A paged array of pets
headers:
x-next:
type: string
description: A link to the next page of responses
schema:
# $ref: '../petstore.yaml/#/definitions/Error' # this ref works, but I don't think it should, this is be referencing one directory up
# $ref: './petstore.yaml/#/definitions/Error' # fails
# $ref: 'petstore.yaml/#/definitions/Error' # fails
# $ref: '../petstore.yaml#/definitions/Error' # works, but I don't think it should, this is be referencing one directory up
# $ref: './petstore.yaml#/definitions/Error' # works
$ref: 'petstore.yaml#/definitions/Error' # works I was adding an additional I am happy to close this issue if you are, though I do think it was a little odd you were not able to reproduce it on your machine. It's possible there's still an environment issue on my end. Thanks. |
ah, I see. So the problem was the For example, if you're in $ref: other.yaml # will resolve to https://example.com/foo/other.yaml
$ref: ./other.yaml # will resolve to https://example.com/foo/other.yaml
$ref: ../other.yaml # will resolve to https://example.com/other.yaml But if you're in $ref: other.yaml # will resolve to https://example.com/foo/bar.yaml/other.yaml
$ref: ./other.yaml # will resolve to https://example.com/foo/bar.yaml/other.yaml
$ref: ../other.yaml # will resolve to https://example.com/foo/other.yaml |
Windows
node v10.7.0
json-schema-ref-parser v5.1.1
petstore.yaml -- root, see full file structure here
code
error
It appears the reference to
pets.yaml
is just getting appended after the fq path to the root file instead of to the directory containing the root file.Any help appreciated.
The text was updated successfully, but these errors were encountered: