openapi-modifier
Version:
This package allows you to automate the process of modifying OpenAPI specifications by applying a set of predefined rules
32 lines (31 loc) • 1.12 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.patchSchema = void 0;
const deepmerge_1 = __importDefault(require("deepmerge"));
const patchSchema = (logger, sourceSchema, method, ...otherSchemas) => {
if (!(otherSchemas === null || otherSchemas === void 0 ? void 0 : otherSchemas.length)) {
return sourceSchema;
}
return otherSchemas.reduce((acc, otherSchema) => {
switch (method) {
case 'deepmerge': {
return (0, deepmerge_1.default)(sourceSchema, otherSchema);
break;
}
case 'merge': {
return Object.assign(Object.assign({}, acc), otherSchema);
break;
}
default: {
logger.warning(`Unknown method type: ${method}`);
return acc;
break;
}
}
return acc;
}, sourceSchema);
};
exports.patchSchema = patchSchema;