UNPKG

openapi-diff

Version:

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

39 lines (38 loc) 2.27 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpecParser = void 0; const parse_openapi3_spec_1 = require("./spec-parser/parse-openapi3-spec"); const parse_swagger2_spec_1 = require("./spec-parser/parse-swagger2-spec"); const resolve_spec_format_1 = require("./spec-parser/resolve-spec-format"); const validate_and_dereference_openapi3_spec_1 = require("./spec-parser/validate-and-dereference-openapi3-spec"); const validate_and_dereference_swagger2_spec_1 = require("./spec-parser/validate-and-dereference-swagger2-spec"); class SpecParser { static parse(spec) { const specFormat = (0, resolve_spec_format_1.resolveSpecFormat)(spec); return specFormat === 'swagger2' ? this.validateAndParseSwagger2(spec.content, spec.location) : this.validateAndParseOpenApi3(spec.content, spec.location); } static validateAndParseSwagger2(content, location) { return __awaiter(this, void 0, void 0, function* () { const spec = yield (0, validate_and_dereference_swagger2_spec_1.validateAndDereferenceSwagger2Spec)(content, location); return (0, parse_swagger2_spec_1.parseSwagger2Spec)(spec); }); } static validateAndParseOpenApi3(content, location) { return __awaiter(this, void 0, void 0, function* () { const spec = yield (0, validate_and_dereference_openapi3_spec_1.validateAndDereferenceOpenapi3Spec)(content, location); return (0, parse_openapi3_spec_1.parseOpenApi3Spec)(spec); }); } } exports.SpecParser = SpecParser;