-
Notifications
You must be signed in to change notification settings - Fork 92
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 is thrown on duplicate keys in resolved remote references #137
Comments
This is a duplicate of #131. |
Only partially. The clobbering of the json-refs error message is one thing, but treating all resolved JSON content as strict YAML breaks the defined behaviour of JSON in that duplicate keys are ignored. |
|
Thanks for the update. In my case the data being returned is JSON not YAML, and so the |
I've tracked it down. There are three players here:
Here are the results: Test YAML ---
definitions:
Person:
properties:
age:
type: integer
age:
type: string
Test JS var fs = require('fs');
var JsonRefs = require('json-refs');
var Sway = require('sway');
var YAML = require('js-yaml');
var docLocation = '/tmp/test.yaml';
function printBad (name, err) {
console.error('Bad document (%s): %s', name, err.message);
}
function printGood (name) {
console.log('Good document (%s)', name);
}
try {
YAML.safeLoad(fs.readFileSync(docLocation, 'utf8'));
printGood('js-yaml');
} catch (err) {
printBad('js-yaml', err)
}
JsonRefs.findRefsAt(docLocation)
.then(function () {
printGood('json-refs');
})
.catch(function (err) {
printBad('json-refs', err);
});
Sway.create({definition: docLocation})
.then(function () {
printGood('sway');
})
.catch(function (err) {
printBad('sway', err);
}); Test Output
Results It seems that if the duplicate key is in the root document, As for the JSON vs. YAML portion of your last response, it's already reported here: whitlockjc/json-refs#101 Long story short, I wanted to avoid having to juggle parsing JSON vs. YAML and since |
Understand. At the moment APIs.guru requires the use of a |
PRs are welcome. |
I believe it is this line responsible.
The error finally reported is not very indicative of the source of the problem:
Would you accept a PR to add options of
{json: true}
to theYAML.safeLoad()
call, possibly controlled by an option setting?Real life example (this PR refers).
The text was updated successfully, but these errors were encountered: