UNPKG

openapi-diff

Version:

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

38 lines (37 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 = parse_openapi3_request_body_1.parseOpenApi3RequestBody(operation.requestBody, pathBuilder.withChild('requestBody'), spec); const responses = 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; exports.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; }, {}); };