Description
First and foremost, this may be a non-issue, I just wanted to confirm the behavior was intended and verify that I am using the library correctly. This also may not be the correct repo for this issue.
I had an issue logged where a user was getting errors in their swagger doc after using multiple $refs to the same file. Example Schema
The following test code demonstrates the issue using the linked schema:
const refParser = require('json-schema-ref-parser')
const path = require('path');
var source = path.join(__dirname, '/schema/petstore.yaml');
refParser.bundle(source, (err, schema) => {
if (err) {
console.error('ERROR:', err);
}
else {
// at this point swagger editor claims the schema is invalid
console.log('SUCCESS:', JSON.stringify(schema, null, 2));
console.log("DEREFERENCE");
refParser.dereference(schema, (err, drSchema) => {
if (err) {
console.error('ERROR:', err);
}
else {
// after a dereference, swagger editor says schema is valid
console.log('SUCCESS:', JSON.stringify(drSchema, null, 2));
}
});
}
});
An initial call to bundle creates a schema that uses local json pointers for the duplicate references. However, this throws errors when copy/pasted into the official Swagger Editor. I noticed that this same bundled schema does not yield any errors when plugged into your Swagger Validator Demo.
After reading through this issue I determined that you must be calling dereference
before doing the validation. When I add a follow up call to dereference, as seen in the test above, the relative json pointers are dereferenced and swagger editor is happy again.
- Is this intended behavior?
- Is calling
bundle
followed bydereference
a suitable workaround, or should I be doing something else in entirely?