api-smart-diff
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -14,5 +14,6 @@ import { Rule } from "./types"; | ||
annotation = "annotation", | ||
unclassified = "unclassified" | ||
unclassified = "unclassified", | ||
deprecate = "deprecate" | ||
} | ||
export declare const breaking: ClassifierType, nonBreaking: ClassifierType, unclassified: ClassifierType, annotation: ClassifierType; | ||
export declare const breaking: ClassifierType, nonBreaking: ClassifierType, unclassified: ClassifierType, annotation: ClassifierType, deprecate: ClassifierType; | ||
export declare const allNonBreaking: Rule; | ||
@@ -24,1 +25,2 @@ export declare const allBreaking: Rule; | ||
export declare const allAnnotation: Rule; | ||
export declare const allDeprecate: Rule; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.allAnnotation = exports.allUnclassified = exports.addNonBreaking = exports.onlyAddBreaking = exports.allBreaking = exports.allNonBreaking = exports.annotation = exports.unclassified = exports.nonBreaking = exports.breaking = exports.ClassifierType = exports.DiffAction = exports.DIFF_META_KEY = void 0; | ||
exports.allDeprecate = exports.allAnnotation = exports.allUnclassified = exports.addNonBreaking = exports.onlyAddBreaking = exports.allBreaking = exports.allNonBreaking = exports.deprecate = exports.annotation = exports.unclassified = exports.nonBreaking = exports.breaking = exports.ClassifierType = exports.DiffAction = exports.DIFF_META_KEY = void 0; | ||
exports.DIFF_META_KEY = "$diff"; | ||
@@ -19,4 +19,5 @@ var DiffAction; | ||
ClassifierType["unclassified"] = "unclassified"; | ||
ClassifierType["deprecate"] = "deprecate"; | ||
})(ClassifierType = exports.ClassifierType || (exports.ClassifierType = {})); | ||
exports.breaking = ClassifierType.breaking, exports.nonBreaking = ClassifierType.nonBreaking, exports.unclassified = ClassifierType.unclassified, exports.annotation = ClassifierType.annotation; | ||
exports.breaking = ClassifierType.breaking, exports.nonBreaking = ClassifierType.nonBreaking, exports.unclassified = ClassifierType.unclassified, exports.annotation = ClassifierType.annotation, exports.deprecate = ClassifierType.deprecate; | ||
// predefined classifiers | ||
@@ -29,2 +30,3 @@ exports.allNonBreaking = [exports.nonBreaking, exports.nonBreaking, exports.nonBreaking]; | ||
exports.allAnnotation = [exports.annotation, exports.annotation, exports.annotation]; | ||
exports.allDeprecate = [exports.deprecate, exports.deprecate, exports.deprecate]; | ||
//# sourceMappingURL=constants.js.map |
@@ -94,3 +94,3 @@ "use strict"; | ||
"/externalDocs": constants_1.allAnnotation, | ||
"/deprecated": booleanClassifier, | ||
"/deprecated": constants_1.allDeprecate, | ||
"/xml": { | ||
@@ -97,0 +97,0 @@ // TODO |
@@ -29,3 +29,3 @@ "use strict"; | ||
const serversRules = { | ||
"/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/": constants_1.allAnnotation, | ||
"/*": { | ||
@@ -43,3 +43,3 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
}, | ||
"/default": [constants_1.breaking, constants_1.breaking, constants_1.breaking], | ||
"/default": [constants_1.nonBreaking, constants_1.nonBreaking, constants_1.breaking], | ||
"/description": constants_1.allAnnotation, | ||
@@ -58,4 +58,4 @@ }, | ||
"/description": constants_1.allAnnotation, | ||
"/required": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/deprecated": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/required": [constants_1.breaking, constants_1.nonBreaking, (ctx) => { var _a; return ((_a = ctx.up().after.schema) === null || _a === void 0 ? void 0 : _a.default) ? constants_1.nonBreaking : (0, utils_1.breakingIfAfterTrue)(ctx); }], | ||
"/deprecated": constants_1.allDeprecate, | ||
}, | ||
@@ -69,3 +69,3 @@ }); | ||
"/required": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/deprecated": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/deprecated": constants_1.allDeprecate, | ||
}, | ||
@@ -97,3 +97,3 @@ }; | ||
"/content": contentRules, | ||
"/required": [constants_1.breaking, constants_1.nonBreaking, (ctx) => (ctx.after ? constants_1.breaking : constants_1.nonBreaking)], | ||
"/required": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
}; | ||
@@ -109,6 +109,26 @@ const responsesRules = { | ||
}; | ||
const securityRules = { | ||
"/": [constants_1.breaking, constants_1.nonBreaking, constants_1.unclassified], | ||
"/*": [constants_1.breaking, constants_1.nonBreaking, constants_1.unclassified], | ||
const globalSecurityRules = { | ||
"/": [ | ||
(ctx) => !(0, utils_1.emptySecurity)(ctx.after) ? constants_1.breaking : constants_1.nonBreaking, | ||
constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.after, ctx.before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => ctx.up().after.length ? constants_1.breaking : constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.up().after, ctx.up().before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
}; | ||
const operationSecurityRules = { | ||
"/": [ | ||
(ctx) => (0, utils_1.emptySecurity)(ctx.after) || (0, utils_1.includeSecurity)(ctx.after, ctx.root.before.security) ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.root.after.security, ctx.before) ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.after, ctx.before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => ctx.up().after.length ? constants_1.breaking : constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.up().after, ctx.up().before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
}; | ||
const operationRules = { | ||
@@ -120,14 +140,14 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/externalDocs": constants_1.allAnnotation, | ||
"/operationId": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/operationId": constants_1.allAnnotation, | ||
"/parameters": parametersRules, | ||
"/requestBody": requestBodiesRules, | ||
"/responses": responsesRules, | ||
"/deprecated": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/security": securityRules, | ||
"/deprecated": constants_1.allDeprecate, | ||
"/security": operationSecurityRules, | ||
"/servers": serversRules, | ||
}; | ||
exports.openapi3Rules = { | ||
"/openapi": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/openapi": constants_1.allAnnotation, | ||
"/info": { | ||
"/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/": constants_1.allAnnotation, | ||
"/title": constants_1.allAnnotation, | ||
@@ -157,3 +177,3 @@ "/description": constants_1.allAnnotation, | ||
"/components": { | ||
"/": [constants_1.nonBreaking, constants_1.nonBreaking, constants_1.nonBreaking], | ||
"/": constants_1.allNonBreaking, | ||
"/schemas": { | ||
@@ -192,3 +212,3 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
}, | ||
"/security": securityRules, | ||
"/security": globalSecurityRules, | ||
"/tags": constants_1.allAnnotation, | ||
@@ -195,0 +215,0 @@ "/externalDocs": constants_1.allAnnotation, |
@@ -31,2 +31,26 @@ "use strict"; | ||
]; | ||
const globalSecurityRules = { | ||
"/": [ | ||
(ctx) => !(0, utils_1.emptySecurity)(ctx.after) ? constants_1.breaking : constants_1.nonBreaking, | ||
constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.after, ctx.before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => ctx.up().after.length ? constants_1.breaking : constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.up().after, ctx.up().before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
}; | ||
const operationSecurityRules = { | ||
"/": [ | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.after, ctx.root.before.security) ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.root.after.security, ctx.before) ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.after, ctx.before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? constants_1.nonBreaking : constants_1.breaking, | ||
(ctx) => ctx.up().after.length ? constants_1.breaking : constants_1.nonBreaking, | ||
(ctx) => (0, utils_1.includeSecurity)(ctx.up().after, ctx.up().before) || (0, utils_1.emptySecurity)(ctx.after) ? constants_1.nonBreaking : constants_1.breaking | ||
], | ||
}; | ||
const nonBreakingIfDefault = ({ after, up }) => { var _a, _b, _c; return ((_c = (_b = (_a = up(2).after) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b[after]) === null || _c === void 0 ? void 0 : _c.default) !== undefined ? constants_1.nonBreaking : constants_1.breaking; }; | ||
@@ -123,6 +147,2 @@ const pathArrayRules = (rules) => (0, utils_1.matchRule)(rules, ({ before, after }) => { | ||
}; | ||
const securityRules = { | ||
"/": [constants_1.breaking, constants_1.nonBreaking, constants_1.unclassified], | ||
"/*": [constants_1.breaking, constants_1.nonBreaking, constants_1.unclassified], | ||
}; | ||
const operationRules = { | ||
@@ -145,4 +165,4 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/responses": responsesRules, | ||
"/deprecated": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
"/security": securityRules | ||
"/deprecated": constants_1.allDeprecate, | ||
"/security": operationSecurityRules | ||
}; | ||
@@ -200,3 +220,3 @@ exports.swagger2Rules = { | ||
}, | ||
"/security": securityRules, | ||
"/security": globalSecurityRules, | ||
"/tags": constants_1.allAnnotation, | ||
@@ -203,0 +223,0 @@ "/externalDocs": constants_1.allAnnotation, |
@@ -12,3 +12,3 @@ export declare type ObjPath = Array<string | number>; | ||
}; | ||
export declare type DiffType = "breaking" | "non-breaking" | "annotation" | "unclassified"; | ||
export declare type DiffType = "breaking" | "non-breaking" | "annotation" | "unclassified" | "deprecate"; | ||
export declare type AddDiffType = DiffType | DiffTypeFunc; | ||
@@ -15,0 +15,0 @@ export declare type RemoveDiffType = DiffType | DiffTypeFunc; |
@@ -56,1 +56,3 @@ import { Rule, MatchFunc, Rules, DiffType, ObjPath, DiffTypeFunc } from "./types"; | ||
export declare const mergeValues: (value: any, patch: any) => any; | ||
export declare const emptySecurity: (value?: any[] | undefined) => boolean; | ||
export declare const includeSecurity: (value?: Array<any>, items?: Array<any>) => boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mergeValues = exports.setValueByPath = exports.getValueByPath = exports.resolveRef = exports.objArray = exports.matchRule = exports.findExternalRefs = exports.getPathMatchFunc = exports.getPathRules = exports.buildPath = exports.parsePath = exports.typeOf = exports.isEmptyObject = exports.unchanged = exports.renamed = exports.replaced = exports.removed = exports.added = exports.breakingIfAfterTrue = exports.breakingIf = exports.PathPointer = void 0; | ||
exports.includeSecurity = exports.emptySecurity = exports.mergeValues = exports.setValueByPath = exports.getValueByPath = exports.resolveRef = exports.objArray = exports.matchRule = exports.findExternalRefs = exports.getPathMatchFunc = exports.getPathRules = exports.buildPath = exports.parsePath = exports.typeOf = exports.isEmptyObject = exports.unchanged = exports.renamed = exports.replaced = exports.removed = exports.added = exports.breakingIfAfterTrue = exports.breakingIf = exports.PathPointer = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -195,2 +195,17 @@ const constants_1 = require("./constants"); | ||
exports.mergeValues = mergeValues; | ||
const emptySecurity = (value) => { | ||
return !!value && (value.length === 0 || (value.length === 1 && Object.keys(value[0]).length === 0)); | ||
}; | ||
exports.emptySecurity = emptySecurity; | ||
const includeSecurity = (value = [], items = []) => { | ||
// TODO match security schema | ||
const valueSet = new Set(value.map((item) => Object.keys(item)[0])); | ||
for (const item of items) { | ||
if (!valueSet.has(Object.keys(item)[0])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
exports.includeSecurity = includeSecurity; | ||
//# sourceMappingURL=utils.js.map |
@@ -14,5 +14,6 @@ import { Rule } from "./types"; | ||
annotation = "annotation", | ||
unclassified = "unclassified" | ||
unclassified = "unclassified", | ||
deprecate = "deprecate" | ||
} | ||
export declare const breaking: ClassifierType, nonBreaking: ClassifierType, unclassified: ClassifierType, annotation: ClassifierType; | ||
export declare const breaking: ClassifierType, nonBreaking: ClassifierType, unclassified: ClassifierType, annotation: ClassifierType, deprecate: ClassifierType; | ||
export declare const allNonBreaking: Rule; | ||
@@ -24,1 +25,2 @@ export declare const allBreaking: Rule; | ||
export declare const allAnnotation: Rule; | ||
export declare const allDeprecate: Rule; |
@@ -16,4 +16,5 @@ export const DIFF_META_KEY = "$diff"; | ||
ClassifierType["unclassified"] = "unclassified"; | ||
ClassifierType["deprecate"] = "deprecate"; | ||
})(ClassifierType || (ClassifierType = {})); | ||
export const { breaking, nonBreaking, unclassified, annotation } = ClassifierType; | ||
export const { breaking, nonBreaking, unclassified, annotation, deprecate } = ClassifierType; | ||
// predefined classifiers | ||
@@ -26,2 +27,3 @@ export const allNonBreaking = [nonBreaking, nonBreaking, nonBreaking]; | ||
export const allAnnotation = [annotation, annotation, annotation]; | ||
export const allDeprecate = [deprecate, deprecate, deprecate]; | ||
//# sourceMappingURL=constants.js.map |
import { breakingIf, breakingIfAfterTrue } from "../utils"; | ||
import { breaking, nonBreaking, addNonBreaking, allAnnotation, allBreaking, allUnclassified, onlyAddBreaking, } from "../constants"; | ||
import { breaking, nonBreaking, addNonBreaking, allAnnotation, allBreaking, allUnclassified, onlyAddBreaking, allDeprecate, } from "../constants"; | ||
const maxClassifier = [ | ||
@@ -91,3 +91,3 @@ breaking, | ||
"/externalDocs": allAnnotation, | ||
"/deprecated": booleanClassifier, | ||
"/deprecated": allDeprecate, | ||
"/xml": { | ||
@@ -94,0 +94,0 @@ // TODO |
@@ -1,4 +0,4 @@ | ||
import { breakingIfAfterTrue, matchRule } from "../utils"; | ||
import { breakingIfAfterTrue, emptySecurity, includeSecurity, matchRule } from "../utils"; | ||
import { jsonSchemaRules } from "./jsonschema"; | ||
import { breaking, nonBreaking, unclassified, allAnnotation, addNonBreaking, allBreaking, } from "../constants"; | ||
import { breaking, nonBreaking, unclassified, allAnnotation, addNonBreaking, allBreaking, allNonBreaking, allDeprecate, } from "../constants"; | ||
const pathArrayRules = (rules) => matchRule(rules, ({ before, after }) => { | ||
@@ -26,3 +26,3 @@ const beforePath = String(before.key).replace(new RegExp("\{.*?\}", "g"), "*"); | ||
const serversRules = { | ||
"/": [nonBreaking, breaking, breaking], | ||
"/": allAnnotation, | ||
"/*": { | ||
@@ -40,3 +40,3 @@ "/": [nonBreaking, breaking, breaking], | ||
}, | ||
"/default": [breaking, breaking, breaking], | ||
"/default": [nonBreaking, nonBreaking, breaking], | ||
"/description": allAnnotation, | ||
@@ -55,4 +55,4 @@ }, | ||
"/description": allAnnotation, | ||
"/required": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/deprecated": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/required": [breaking, nonBreaking, (ctx) => { var _a; return ((_a = ctx.up().after.schema) === null || _a === void 0 ? void 0 : _a.default) ? nonBreaking : breakingIfAfterTrue(ctx); }], | ||
"/deprecated": allDeprecate, | ||
}, | ||
@@ -66,3 +66,3 @@ }); | ||
"/required": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/deprecated": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/deprecated": allDeprecate, | ||
}, | ||
@@ -94,3 +94,3 @@ }; | ||
"/content": contentRules, | ||
"/required": [breaking, nonBreaking, (ctx) => (ctx.after ? breaking : nonBreaking)], | ||
"/required": [breaking, nonBreaking, breakingIfAfterTrue], | ||
}; | ||
@@ -106,6 +106,26 @@ const responsesRules = { | ||
}; | ||
const securityRules = { | ||
"/": [breaking, nonBreaking, unclassified], | ||
"/*": [breaking, nonBreaking, unclassified], | ||
const globalSecurityRules = { | ||
"/": [ | ||
(ctx) => !emptySecurity(ctx.after) ? breaking : nonBreaking, | ||
nonBreaking, | ||
(ctx) => includeSecurity(ctx.after, ctx.before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? nonBreaking : breaking, | ||
(ctx) => ctx.up().after.length ? breaking : nonBreaking, | ||
(ctx) => includeSecurity(ctx.up().after, ctx.up().before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
}; | ||
const operationSecurityRules = { | ||
"/": [ | ||
(ctx) => emptySecurity(ctx.after) || includeSecurity(ctx.after, ctx.root.before.security) ? nonBreaking : breaking, | ||
(ctx) => includeSecurity(ctx.root.after.security, ctx.before) ? nonBreaking : breaking, | ||
(ctx) => includeSecurity(ctx.after, ctx.before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? nonBreaking : breaking, | ||
(ctx) => ctx.up().after.length ? breaking : nonBreaking, | ||
(ctx) => includeSecurity(ctx.up().after, ctx.up().before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
}; | ||
const operationRules = { | ||
@@ -117,14 +137,14 @@ "/": [nonBreaking, breaking, breaking], | ||
"/externalDocs": allAnnotation, | ||
"/operationId": [nonBreaking, breaking, breaking], | ||
"/operationId": allAnnotation, | ||
"/parameters": parametersRules, | ||
"/requestBody": requestBodiesRules, | ||
"/responses": responsesRules, | ||
"/deprecated": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/security": securityRules, | ||
"/deprecated": allDeprecate, | ||
"/security": operationSecurityRules, | ||
"/servers": serversRules, | ||
}; | ||
export const openapi3Rules = { | ||
"/openapi": [nonBreaking, breaking, breaking], | ||
"/openapi": allAnnotation, | ||
"/info": { | ||
"/": [nonBreaking, breaking, breaking], | ||
"/": allAnnotation, | ||
"/title": allAnnotation, | ||
@@ -154,3 +174,3 @@ "/description": allAnnotation, | ||
"/components": { | ||
"/": [nonBreaking, nonBreaking, nonBreaking], | ||
"/": allNonBreaking, | ||
"/schemas": { | ||
@@ -189,3 +209,3 @@ "/": [nonBreaking, breaking, breaking], | ||
}, | ||
"/security": securityRules, | ||
"/security": globalSecurityRules, | ||
"/tags": allAnnotation, | ||
@@ -192,0 +212,0 @@ "/externalDocs": allAnnotation, |
@@ -1,3 +0,3 @@ | ||
import { breakingIf, breakingIfAfterTrue, matchRule } from "../utils"; | ||
import { breaking, nonBreaking, unclassified, allAnnotation, addNonBreaking, allBreaking, allUnclassified, onlyAddBreaking, } from "../constants"; | ||
import { breakingIf, breakingIfAfterTrue, emptySecurity, includeSecurity, matchRule } from "../utils"; | ||
import { breaking, nonBreaking, allAnnotation, addNonBreaking, allBreaking, allUnclassified, onlyAddBreaking, allDeprecate, } from "../constants"; | ||
const maxClassifier = [ | ||
@@ -28,2 +28,26 @@ breaking, | ||
]; | ||
const globalSecurityRules = { | ||
"/": [ | ||
(ctx) => !emptySecurity(ctx.after) ? breaking : nonBreaking, | ||
nonBreaking, | ||
(ctx) => includeSecurity(ctx.after, ctx.before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? nonBreaking : breaking, | ||
(ctx) => ctx.up().after.length ? breaking : nonBreaking, | ||
(ctx) => includeSecurity(ctx.up().after, ctx.up().before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
}; | ||
const operationSecurityRules = { | ||
"/": [ | ||
(ctx) => includeSecurity(ctx.after, ctx.root.before.security) ? nonBreaking : breaking, | ||
(ctx) => includeSecurity(ctx.root.after.security, ctx.before) ? nonBreaking : breaking, | ||
(ctx) => includeSecurity(ctx.after, ctx.before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
"/*": [ | ||
(ctx) => ctx.up().before.length ? nonBreaking : breaking, | ||
(ctx) => ctx.up().after.length ? breaking : nonBreaking, | ||
(ctx) => includeSecurity(ctx.up().after, ctx.up().before) || emptySecurity(ctx.after) ? nonBreaking : breaking | ||
], | ||
}; | ||
const nonBreakingIfDefault = ({ after, up }) => { var _a, _b, _c; return ((_c = (_b = (_a = up(2).after) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b[after]) === null || _c === void 0 ? void 0 : _c.default) !== undefined ? nonBreaking : breaking; }; | ||
@@ -120,6 +144,2 @@ const pathArrayRules = (rules) => matchRule(rules, ({ before, after }) => { | ||
}; | ||
const securityRules = { | ||
"/": [breaking, nonBreaking, unclassified], | ||
"/*": [breaking, nonBreaking, unclassified], | ||
}; | ||
const operationRules = { | ||
@@ -142,4 +162,4 @@ "/": [nonBreaking, breaking, breaking], | ||
"/responses": responsesRules, | ||
"/deprecated": [breaking, nonBreaking, breakingIfAfterTrue], | ||
"/security": securityRules | ||
"/deprecated": allDeprecate, | ||
"/security": operationSecurityRules | ||
}; | ||
@@ -197,3 +217,3 @@ export const swagger2Rules = { | ||
}, | ||
"/security": securityRules, | ||
"/security": globalSecurityRules, | ||
"/tags": allAnnotation, | ||
@@ -200,0 +220,0 @@ "/externalDocs": allAnnotation, |
@@ -12,3 +12,3 @@ export declare type ObjPath = Array<string | number>; | ||
}; | ||
export declare type DiffType = "breaking" | "non-breaking" | "annotation" | "unclassified"; | ||
export declare type DiffType = "breaking" | "non-breaking" | "annotation" | "unclassified" | "deprecate"; | ||
export declare type AddDiffType = DiffType | DiffTypeFunc; | ||
@@ -15,0 +15,0 @@ export declare type RemoveDiffType = DiffType | DiffTypeFunc; |
@@ -56,1 +56,3 @@ import { Rule, MatchFunc, Rules, DiffType, ObjPath, DiffTypeFunc } from "./types"; | ||
export declare const mergeValues: (value: any, patch: any) => any; | ||
export declare const emptySecurity: (value?: any[] | undefined) => boolean; | ||
export declare const includeSecurity: (value?: Array<any>, items?: Array<any>) => boolean; |
@@ -171,2 +171,15 @@ import { __rest } from "tslib"; | ||
}; | ||
export const emptySecurity = (value) => { | ||
return !!value && (value.length === 0 || (value.length === 1 && Object.keys(value[0]).length === 0)); | ||
}; | ||
export const includeSecurity = (value = [], items = []) => { | ||
// TODO match security schema | ||
const valueSet = new Set(value.map((item) => Object.keys(item)[0])); | ||
for (const item of items) { | ||
if (!valueSet.has(Object.keys(item)[0])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "api-smart-diff", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "Generate the diff between two API specifications (OpenAPI, AsyncAPI, JsonSchema)", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
@@ -47,3 +47,3 @@ # api-smart-diff | ||
// path: ['path, 'in', 'array', 'format'], | ||
// type: "annotation" | "breaking" | "non-breaking" | "unclassified" | ||
// type: "annotation" | "breaking" | "non-breaking" | "unclassified" | "deprecate" | ||
// } | ||
@@ -115,3 +115,3 @@ | ||
after?: any | ||
type: "breaking" | "non-breaking" | "annotation" | "unclassified" | ||
type: "breaking" | "non-breaking" | "annotation" | "unclassified" | "deprecate" | ||
} | ||
@@ -141,3 +141,3 @@ ``` | ||
after?: any | ||
type: "breaking" | "non-breaking" | "annotation" | "unclassified" | ||
type: "breaking" | "non-breaking" | "annotation" | "unclassified" | "deprecate" | ||
} | ||
@@ -144,0 +144,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
384381
5354