swag-webhook-events/plugins/local.js
Inal Arsanukaev 9f0c660a8c
TD-138: github actions, openapi 3.0 (#5)
* 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>
2022-02-11 18:17:07 +03:00

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];
}
}
}
}