mirror of
https://github.com/valitydev/swag-webhook-events.git
synced 2024-11-06 02:15:22 +00:00
9f0c660a8c
* TD-138: github actions, openapi 3.0 * Fix .gitignore * Fix pom.xml * Fix signature.yaml * Fix path * Fix openapi.yaml * Fix openapi.yaml * Removed property 'name' * Added 404 error * Change server to client * Feedback fixes Co-authored-by: Inal Arsanukaev <inalarsanukaev@192.168.1.5>
51 lines
1.2 KiB
JavaScript
51 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);
|
|
console.log(merged);
|
|
};
|
|
Object.assign(node, merged);
|
|
delete node[trigger];
|
|
}
|
|
}
|
|
}
|
|
}
|