UNPKG

openapi-diff

Version:

A CLI tool to identify differences between Swagger/OpenAPI specs.

40 lines (39 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseOpenApi3Operations = void 0; const parse_openapi3_request_body_1 = require("./parse-openapi3-request-body"); const parse_openapi3_responses_1 = require("./parse-openapi3-responses"); const parseOperation = (operation, pathBuilder, spec) => { const requestBody = (0, parse_openapi3_request_body_1.parseOpenApi3RequestBody)(operation.requestBody, pathBuilder.withChild('requestBody'), spec); const responses = (0, parse_openapi3_responses_1.parseOpenApi3Responses)(operation.responses, pathBuilder.withChild('responses'), spec); return { originalValue: { originalPath: pathBuilder.build(), value: operation }, requestBody, responses }; }; const typeCheckedOpenApi3Methods = { delete: undefined, get: undefined, head: undefined, options: undefined, patch: undefined, post: undefined, put: undefined, trace: undefined }; const isOpenApi3Method = (propertyName) => Object.keys(typeCheckedOpenApi3Methods).indexOf(propertyName) >= 0; const parseOpenApi3Operations = (pathItemObject, pathBuilder, spec) => { return Object.keys(pathItemObject) .filter(isOpenApi3Method) .reduce((accumulator, method) => { const operationObject = pathItemObject[method]; const originalPath = pathBuilder.withChild(method); accumulator[method] = parseOperation(operationObject, originalPath, spec); return accumulator; }, {}); }; exports.parseOpenApi3Operations = parseOpenApi3Operations;