UNPKG

openapi-diff

Version:

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

61 lines (60 loc) 2.72 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.OpenApiDiff = void 0; const spec_differ_1 = require("./openapi-diff/spec-differ"); class OpenApiDiff { constructor(contentLoader, resultReporter) { this.contentLoader = contentLoader; this.resultReporter = resultReporter; } diffPaths(diffPathOptions) { return __awaiter(this, void 0, void 0, function* () { try { const diffSpecOptions = yield this.toDiffSpecsOptions(diffPathOptions); const diffOutcome = yield this.diffSpecs(diffSpecOptions); this.resultReporter.reportOutcome(diffOutcome); if (diffOutcome.breakingDifferencesFound) { return Promise.reject(new Error('Breaking differences found')); } } catch (error) { this.resultReporter.reportError(error); throw error; } }); } diffSpecs(options) { return __awaiter(this, void 0, void 0, function* () { return spec_differ_1.SpecDiffer.diffSpecs(options); }); } toDiffSpecsOptions({ sourceSpec, destinationSpec }) { return __awaiter(this, void 0, void 0, function* () { const [sourceSerialisedSpec, destinationSerialisedSpec] = yield Promise.all([ this.toSerialisedSpec(sourceSpec), this.toSerialisedSpec(destinationSpec) ]); return { sourceSpec: sourceSerialisedSpec, destinationSpec: destinationSerialisedSpec }; }); } toSerialisedSpec(specReference) { return __awaiter(this, void 0, void 0, function* () { const serializedContent = yield this.contentLoader.load(specReference.location); return { content: serializedContent, format: specReference.format, location: specReference.location }; }); } } exports.OpenApiDiff = OpenApiDiff;