openapi-diff
Version:
A CLI tool to identify differences between Swagger/OpenAPI specs.
24 lines (23 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const dereference_object_1 = require("../common/dereference-object");
const parse_swagger2_body_object_json_schema_1 = require("./parse-swagger2-body-object-json-schema");
const parse_swagger2_response_headers_1 = require("./parse-swagger2-response-headers");
const parseResponse = (responseOrReference, pathBuilder, spec) => {
const response = dereference_object_1.dereferenceObject(responseOrReference, spec);
return {
headers: parse_swagger2_response_headers_1.parseSwagger2ResponseHeaders(response, pathBuilder),
jsonSchema: parse_swagger2_body_object_json_schema_1.parseSwagger2BodyObjectJsonSchema(response, pathBuilder, spec),
originalValue: {
originalPath: pathBuilder.build(),
value: responseOrReference
}
};
};
exports.parseSwagger2Responses = (responses, pathBuilder, spec) => {
return Object.keys(responses).reduce((accumulator, statusCode) => {
const originalPath = pathBuilder.withChild(statusCode);
accumulator[statusCode] = parseResponse(responses[statusCode], originalPath, spec);
return accumulator;
}, {});
};