mirror of
https://github.com/valitydev/swag-disputes.git
synced 2024-11-06 09:05:20 +00:00
d5286d5700
* IMP-299L impl proto * IMP-299: impl proto * IMP-299: impl proto * IMP-299: impl proto * IMP-299: impl proto * IMP-299: feedback edits
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
const jsonmergepatch = require('json-merge-patch');
|
|
|
|
module.exports = {
|
|
|
|
id: 'local',
|
|
|
|
preprocessors: {
|
|
oas3: {
|
|
'merge-schemas': MergeSchemas
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
function MergeSchemas() {
|
|
const trigger = 'x-mergeSchemas';
|
|
return {
|
|
Schema: {
|
|
leave(node, ctx) {
|
|
if (!node[trigger]) {
|
|
return;
|
|
}
|
|
var schemas = node[trigger];
|
|
if (!Array.isArray(schemas)) {
|
|
return ctx.report({
|
|
message: "Argument should be an array of schemas",
|
|
location: ctx.location.child(trigger)
|
|
});
|
|
}
|
|
let merged = null;
|
|
for (index = schemas.length - 1; index >= 0; --index) {
|
|
let schema = schemas[index];
|
|
if (typeof schema !== 'object') {
|
|
return ctx.report({
|
|
message: "Non-object value",
|
|
location: ctx.location.child(trigger).child(index)
|
|
});
|
|
}
|
|
if (schema.$ref && typeof schema.$ref === 'string') {
|
|
schema = ctx.resolve(schema).node;
|
|
}
|
|
merged = jsonmergepatch.apply(merged, schema);
|
|
};
|
|
Object.assign(node, merged);
|
|
delete node[trigger];
|
|
}
|
|
}
|
|
}
|
|
}
|