openapi-modifier
Version:
This package allows you to automate the process of modifying OpenAPI specifications by applying a set of predefined rules
19 lines (18 loc) • 992 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOperationSchema = void 0;
const openapi_models_1 = require("../openapi-models");
const normilizers_1 = require("./normilizers");
const getOperationSchema = (openAPIFile, path, method) => {
var _a, _b;
const pathObjSchema = (_b = (_a = openAPIFile === null || openAPIFile === void 0 ? void 0 : openAPIFile.document) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b[path];
const methods = Object.keys(pathObjSchema || {}).filter(openapi_models_1.checkIsHttpMethod);
const targetMethod = methods.find((pathMethod) => {
return (0, normilizers_1.normalizeMethod)(pathMethod) === (0, normilizers_1.normalizeMethod)(method);
});
if (!targetMethod) {
return null;
}
return (pathObjSchema === null || pathObjSchema === void 0 ? void 0 : pathObjSchema[targetMethod]) || null;
};
exports.getOperationSchema = getOperationSchema;