openapi-diff
Version:
A CLI tool to identify differences between Swagger/OpenAPI specs.
33 lines (32 loc) • 1.73 kB
JavaScript
;
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.getSchemaDifferences = exports.getJsonSchemaForDiffing = void 0;
const JsonSchemaDiff = require("json-schema-diff");
const open_api_diff_error_impl_1 = require("../../../common/open-api-diff-error-impl");
const getJsonSchemaForDiffing = (parsedScope) => {
return parsedScope.jsonSchema
? parsedScope.jsonSchema.schema
: {};
};
exports.getJsonSchemaForDiffing = getJsonSchemaForDiffing;
const getSchemaDifferences = (sourceParsedScope, destinationParsedScope) => __awaiter(void 0, void 0, void 0, function* () {
try {
return yield JsonSchemaDiff.diffSchemas({
destinationSchema: (0, exports.getJsonSchemaForDiffing)(destinationParsedScope),
sourceSchema: (0, exports.getJsonSchemaForDiffing)(sourceParsedScope)
});
}
catch (error) {
throw new open_api_diff_error_impl_1.OpenApiDiffErrorImpl('OPENAPI_DIFF_DIFF_ERROR', error);
}
});
exports.getSchemaDifferences = getSchemaDifferences;