UNPKG

openapi-diff

Version:

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

64 lines (63 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getScopeRemoveDifferences = exports.getScopeAddDifferences = void 0; const create_difference_1 = require("./create-difference"); const defaultJsonSchemaDetails = () => ({ isDefinedInOrigin: false, path: [] }); const toJsonSchemaDetails = (parsedScope) => { return parsedScope.jsonSchema === undefined ? defaultJsonSchemaDetails() : { isDefinedInOrigin: true, path: parsedScope.jsonSchema.originalValue.originalPath }; }; const createSpecOrigins = (parsedScope) => { const jsonSchemaDetails = toJsonSchemaDetails(parsedScope); const originValue = parsedScope.jsonSchema ? parsedScope.jsonSchema.originalValue.value : undefined; return jsonSchemaDetails.isDefinedInOrigin ? [{ originalPath: jsonSchemaDetails.path, value: originValue }] : []; }; const createScopeDifference = (options) => (0, create_difference_1.createDifference)({ action: options.action, destinationSpecOrigins: createSpecOrigins(options.destinationParsedScope), details: { differenceSchema: options.differenceSchema }, propertyName: options.propertyName, source: 'json-schema-diff', sourceSpecOrigins: createSpecOrigins(options.sourceParsedScope) }); const getScopeAddDifferences = (options) => { if (!options.additionsFound) { return []; } return [ createScopeDifference({ action: 'add', destinationParsedScope: options.destinationScope, differenceSchema: options.addedJsonSchema, propertyName: options.propertyName, sourceParsedScope: options.sourceScope }) ]; }; exports.getScopeAddDifferences = getScopeAddDifferences; const getScopeRemoveDifferences = (options) => { if (!options.removalsFound) { return []; } return [ createScopeDifference({ action: 'remove', destinationParsedScope: options.destinationScope, differenceSchema: options.removedJsonSchema, propertyName: options.propertyName, sourceParsedScope: options.sourceScope }) ]; }; exports.getScopeRemoveDifferences = getScopeRemoveDifferences;