api-smart-diff
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -1,2 +0,2 @@ | ||
/*! api-smart-diff@0.4.4 */ | ||
var ApiSmartDiff=function(r){var n={};function a(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.l=!0,t.exports}return a.m=r,a.c=n,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(I,e,t){"use strict";t.r(e),t.d(e,"messageTraitsRules",function(){return W}),t.d(e,"messageRules",function(){return X}),t.d(e,"asyncApi2Rules",function(){return Z}),t.d(e,"openapi3Rules",function(){return ee}),t.d(e,"jsonSchemaRules",function(){return P}),t.d(e,"serviceNodeRules",function(){return ne}),t.d(e,"DIFF_META_KEY",function(){return q}),t.d(e,"DiffAction",function(){return d}),t.d(e,"ClassifierType",function(){return r}),t.d(e,"breaking",function(){return n}),t.d(e,"nonBreaking",function(){return a}),t.d(e,"unclassified",function(){return s}),t.d(e,"annotation",function(){return i}),t.d(e,"allNonBreaking",function(){return o}),t.d(e,"allBreaking",function(){return c}),t.d(e,"onlyAddBreaking",function(){return f}),t.d(e,"addNonBreaking",function(){return u}),t.d(e,"allUnclassified",function(){return l}),t.d(e,"allAnnotation",function(){return h}),t.d(e,"PathPointer",function(){return B}),t.d(e,"breakingIf",function(){return p}),t.d(e,"breakingIfAfterTrue",function(){return m}),t.d(e,"added",function(){return j}),t.d(e,"removed",function(){return A}),t.d(e,"replaced",function(){return V}),t.d(e,"renamed",function(){return F}),t.d(e,"unchanged",function(){return g}),t.d(e,"isEmptyObject",function(){return b}),t.d(e,"typeOf",function(){return v}),t.d(e,"parsePath",function(){return K}),t.d(e,"buildPath",function(){return U}),t.d(e,"getPathRules",function(){return N}),t.d(e,"getPathMatchFunc",function(){return z}),t.d(e,"findExternalRefs",function(){return L}),t.d(e,"matchRule",function(){return O}),t.d(e,"objArray",function(){return M}),t.d(e,"resolveRef",function(){return R}),t.d(e,"getValueByPath",function(){return J}),t.d(e,"setValueByPath",function(){return Y}),t.d(e,"mergeValues",function(){return k}),t.d(e,"ApiCompare",function(){return $}),t.d(e,"JsonCompare",function(){return ae}),t.d(e,"apiDiff",function(){return oe}),t.d(e,"apiMerge",function(){return ce}),t.d(e,"apiDiffTree",function(){return fe});var d,r;function y(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}const q="$diff",{breaking:n,nonBreaking:a,unclassified:s,annotation:i}=((t=d=d||{}).add="add",t.remove="remove",t.replace="replace",t.rename="rename",t.test="test",(e=r=r||{}).breaking="breaking",e.nonBreaking="non-breaking",e.annotation="annotation",e.unclassified="unclassified",r),o=[a,a,a],c=[n,n,n],f=[n,a,a],u=[a,n,n],l=[s,s,s],h=[i,i,i];class B{constructor(e,t){this.key=e,this.parent=t,this.items=[],void 0===e?this.escapedKey="":(this.escapedKey="string"==typeof e?e.replace(new RegExp("~1","g"),"/"):String(e),this.items=t?[...t.items,e]:[e])}get ref(){return this.parent?this.parent.ref+"/"+this.escapedKey:this.escapedKey}[Symbol.iterator](){let e=0;return{next:()=>({done:!(e<this.items.length),value:this.items[e++]})}}childPath(e){return new B(e,this)}}const p=e=>e?n:a,m=({after:e})=>p(e),j=(e,t)=>({path:e.items,after:t,action:d.add}),A=(e,t)=>({path:e.items,before:t,action:d.remove}),V=(e,t,r)=>({path:e.items,before:t,after:r,action:d.replace}),F=(e,t,r)=>({path:e.items,before:t,after:r,action:d.rename}),g=(e,t)=>({path:e.items,before:t,action:d.test}),b=e=>{for(const t in e)return!1;return!0},v=e=>Array.isArray(e)?"array":null==e?"null":typeof e,K=e=>{var[,...e]=e.split("/").map(e=>e.replace(new RegExp("~1","g"),"/"));return e},U=e=>"/"+e.map(e=>String(e).replace(new RegExp("/","g"),"~1")).join("/"),N=(e,t,r)=>{let n=e,a=r;for(var s of[...t]){if(a=void 0!==s&&void 0!==a?a[s]:void 0,n.hasOwnProperty("/"+s)&&"number"!=typeof s||(s="*"),!n.hasOwnProperty("/"+s))return;{const i=n["/"+s];if(Array.isArray(i))return i;n="function"==typeof i?i(a):i}}return n},z=(e,t,r)=>{e=N(e,t.items,r);return e&&!Array.isArray(e)?e["#"]:void 0},L=e=>{if("object"!=typeof e)return[];let t=new Set;if("array"===v(e))for(const n of e)"object"==typeof n&&(t=new Set([...t,...L(n)]));else for(const a of Object.keys(e)){var r;"$ref"===a?([r]=e[a].split("#"),r&&t.add(r)):"object"==typeof e[a]&&(t=new Set([...t,...L(e[a])]))}return[...t]},O=(e,t)=>(e["#"]=t,e),M=(r,e)=>O(e,({before:e,after:t})=>t.value[r]===e.value[r]),R=(e,t,r)=>{const n=e["$ref"],a=y(e,["$ref"]);if(n){var[s,i]=n.split("#");if(s&&!r.has(s))return e;r=J(s?r.get(s):t,K(i));return b(a)?r:k(r,a)}return e},J=(e,t)=>{let r=e;for(const n of t)if(void 0===(r="array"===v(r)?r[+n]:r[n]))break;return r},Y=(e,t,r,n=0)=>{var a;n>=t.length||("object"!=typeof e[a=t[n]]&&(e[a]={}),n===t.length-1?e[a]=r:Y(e[a],t,r,n+1))},k=(e,t)=>{if(Array.isArray(e))return Array.isArray(t)?e.push(...t):e;if("object"!=typeof e||"object"!=typeof t)return t;for(const r of Reflect.ownKeys(t))e[r]=k(e[r],t[r]);return e},x=[n,a,({before:e,after:t})=>p(t<e)],w=[n,a,({before:e,after:t})=>p(e<t)],G=[m,a,m],S=[m,a,m],H=[n,a,({before:e,after:t})=>p(!!(e%t))],Q=({after:e,up:t})=>{return void 0!==(null==(t=null==(t=null==(t=t(2).after)?void 0:t.properties)?void 0:t[e])?void 0:t.default)?a:n},P=(e=l)=>({"/":e,"/title":h,"/multipleOf":H,"/maximum":x,"/exclusiveMaximum":G,"/minimum":w,"/exclusiveMinimum":G,"/maxLength":x,"/minLength":w,"/pattern":[n,a,n],"/maxItems":x,"/minItems":w,"/uniqueItems":S,"/maxProperties":x,"/minProperties":w,"/required":{"/":f,"/*":[Q,a,Q]},"/enum":{"/":[n,a,n],"/*":[a,n,n]},"/type":[n,a,n],"/not":{"/":[n,a,n],"/*":()=>P(c)},"/allOf":{"/":[n,a,n],"/*":()=>P(c)},"/oneOf":{"/":[n,a,n],"/*":()=>P(u)},"/anyOf":{"/":[n,a,n],"/*":()=>P(u)},"/items":()=>P(u),"/properties":{"/":[n,a,n],"/*":()=>P(u)},"/additionalProperties":()=>P([n,n,m]),"/description":h,"/format":[n,a,n],"/default":[a,n,n],"/nullable":S,"/discriminator":{"/":l,"/propertyName":l,"/mapping":l},"/readOnly":S,"/writeOnly":S,"/example":h,"/examples":h,"/externalDocs":h,"/deprecated":S,"/xml":{"/":l,"/name":l,"/namespace":l,"/prefix":l,"/attribute":l,"/wrapped":l}});var t={"/":u,"/location":u,"/description":h},e={"/summary":h,"/tags":h,"/externalDocs":h,"/bindings":l},_=Object.assign({"/":u,"/*":u,"/operationId":u,"/description":h},e);const W=Object.assign({"/":u,"/*":u,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/examples":h},e),X=Object.assign({"/":c,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/description":o,"/examples":h,"/traits":W,"/payload":P(c)},e);t=Object.assign({"/":u,"/operationId":u,"/description":h,"/traits":_,"/message":X},e),_={"/":u,"/version":u,"/termsOfService":u,"/license":{"/":u,"/name":c,"/url":f},"/title":h,"/description":h,"/contact":{"/":h,"/name":h,"/url":h,"/email":h}},e={"/":u,"/*":{"/":u,"/url":u,"/description":h,"/protocol":c,"/protocolVersion":c,"/variables":{"/":u,"/*":{"/":u,"/enum":{"/":u,"/*":u},"/default":c,"/description":h,"/examples":h}},"/security":{"/":c,"/*":c},"/bindings":l}},t={"/":u,"/description":o,"/bindings":l,"/subscribe":t,"/publish":t,"/parameters":{"/":c,"/*":{"/":u,"/description":o,"/schema":P(c),"/location":c}}};const Z={"/asyncapi":u,"/id":h,"/defaultContentType":c,"/info":_,"/servers":e,"/channels":{"/":u,"/*":t},"/components":o,"/tags":h,"/externalDocs":h};var _={"/":[a,n,n],"/*":{"/":[a,n,n],"/url":[a,n,n],"/description":h,"/variables":{"/":[a,n,n],"/*":{"/":[a,n,n],"/enum":{"/":[a,n,n],"/*":[a,n,n]},"/default":[n,n,n],"/description":h}}}},e={"/":[a,n,n],"/*":{"/":[a,n,n],"/name":[a,n,e=>{return"path"===(null==(e=e.up().before)?void 0:e.in)?a:n}],"/in":[a,n,n],"/description":h,"/required":[n,a,m],"/deprecated":[n,a,m]}},t={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":h,"/required":[n,a,m],"/deprecated":[n,a,m]}},T={"/":[a,a,a],"/*":{"/contentType":[a,n,n],"/headers":t,"/style":[a,n,n],"/explode":[a,n,n],"/allowReserved":[a,n,n]}},T={"/":[a,n,n],"/*":{"/":[a,n,n],"/schema":P(c),"/example":h,"/examples":h,"/encoding":T}},C={"/":[a,n,n],"/description":h,"/content":T,"/required":[n,a,e=>e.after?n:a]},T={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":h,"/headers":t,"/content":T}},D={"/":[n,a,s],"/*":[n,a,s]},E={"/":[a,n,n],"/tags":h,"/summary":h,"/description":h,"/externalDocs":h,"/operationId":[a,n,n],"/parameters":e,"/requestBody":C,"/responses":T,"/deprecated":[n,a,m],"/security":D,"/servers":_};const ee={"/openapi":[a,n,n],"/info":{"/":[a,n,n],"/title":h,"/description":h,"/termsOfService":h,"/contact":h,"/licence":{"/":[a,n,n],"/name":[n,n,n],"/url":[n,a,a]},"/version":h},"/servers":_,"/paths":(E={"/":[a,n,n],"/*":{"/":[a,n,a],"/summary":h,"/description":h,"/*":E,"/servers":_,"/parameters":e}},O(E,({before:e,after:t})=>{return String(e.key).replace(new RegExp("{.*?}","g"),"*")===String(t.key).replace(new RegExp("{.*?}","g"),"*")})),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)},"/responses":{"/":[a,n,n],"/*":T},"/parameters":{"/":[a,n,n],"/*":e},"/examples":h,"/requestBodies":{"/":[a,n,n],"/*":C},"/headers":t,"/securitySchemes":{"/":[n,a,n],"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":h,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":h,"/flows":[n,a,n],"/openIdConnectUrl":h}}},"/security":D,"/tags":h,"/externalDocs":h};_=e=>O(e,({before:{value:e},after:{value:t}})=>{var r;return t.type===e.type&&("model"===t.type?t.name===e.name:(null==(r=e.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))===(null==(r=t.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))&&e.data.method===t.data.method)}),E={"/name":[a,n,n],"/style":l,"/description":h,"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]},T={"/":[a,n,n],"/*":E},e={"/":u,"/*":{"/":[a,n,n],"/mediaType":[a,n,n],"/schema":P(c),"/examples":M("key",{"/":h,"/*":h}),"/encodings":[a,n,n]}},C={"/path":M("name",T),"/query":M("name",{"/":[a,n,n],"/*":Object.assign(Object.assign({},E),{"/allowEmptyValue":[n,a,m],"/allowReserved":[n,a,m]})}),"/headers":M("name",T),"/cookie":M("name",T),"/body":{"/":[a,n,n],"/contents":M("mediaType",e),"/required":[n,a,m],"/description":h}},t={"/":l,"/*":{"/name":[a,n,n],"/style":l,"/description":h,"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]}},D={"/":u,"/*":{"/":u,"/code":l,"/contents":M("mediaType",e),"/headers":M("name",t),"/description":h}},E={"/":[a,n,n],"/url":[a,n,n],"/name":h,"/description":h,"/variables":[a,n,n]},T={"/":[n,a,s],"/*":[n,a,s]};const te={"/":[a,n,n],"/data":()=>P(u),"/*":h},re={"/":[a,n,n],"/data":{"/id":h,"/iid":h,"/tags":h,"/summary":h,"/description":h,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/servers":{"/":l,"/*":E},"/callbacks":_({"/callbackName":h,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/deprecated":l,"/internal":l,"/extensions":l}),"/security":T,"/deprecated":[n,a,m],"/internal":l,"/extensions":l},"/*":h};e={"/id":h,"/iid":h,"/tags":h,"/summary":h,"/description":h,"/name":h,"/version":h,"/servers":{"/":[a,n,n],"/*":E},"/security":T,"/securitySchemes":M("name",{"/":u,"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":h,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":h,"/flows":[n,a,n],"/openIdConnectUrl":h}}),"/termsOfService":h,"/contact":h,"/license":[n,n,n],"/logo":h};const ne={"/*":h,"/data":e,"/children":_({"/":[a,n,n],"/*":({type:e})=>"model"===e?te:re}),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)}}};class ae{constructor(e,t,r={}){this.before=e,this.after=t,this._merged={},this._formatMergeMeta=e=>Object.assign({action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.trimStrings=r.trimStrings,this.caseSensitive=r.caseSensitive,this.strictArrays=r.strictArrays,this.matchRules=r.matchRules||{},this.diffKey=r.metaKey||q,this.arrayMeta=r.arrayMeta,this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this)}get merged(){return this._merged.value}setMeta(e,t,r){void 0===e[this.diffKey]&&(e[this.diffKey]={}),e[this.diffKey][t]=r}checkMatch(e,t,r,n,a){const s=this.getMatchFunc(e);return!!s&&s({path:e.items,before:{key:n,value:t[n],parent:t,source:this.before},after:{key:a,value:r[a],parent:r,source:this.after}})}getMatchFunc(e){e=e.ref;return this.matchRules[e]}compare(){return this.compareAny(this.before,this.after).diffs}buildDiffTree(){return this.compareAny(this.before,this.after).diffTree}merge(){return this.compareAny(this.before,this.after),this._merged.value}normalizeString(e){return e=this.trimStrings?e.trim():e,e=this.caseSensitive?e:e.toLowerCase()}mergeResults(e,t,r=!1){const n={diffs:[],diffTree:{}};for(var a of Object.keys(e)){var s,i,{diffs:o,diff:c,diffTree:f,parentMeta:u}=e[a];c&&c.action!==d.test?(i=c["path"],s=y(c,["path"]),i=i[i.length-1],this.setMeta(n.diffTree,i,s),n.diffs.push(c),r&&!this.arrayMeta?(void 0===n.parentMeta&&(n.parentMeta={}),n.parentMeta[i]=this.formatMergedMeta(c)):c.action===d.rename?this.setMeta(t,c.after,this.formatMergedMeta(c)):this.setMeta(t,i,this.formatMergedMeta(c)),a):(o.length&&(n.diffTree[a]=f,n.diffs.push(...o)),u&&this.setMeta(t,r?+a:a,{array:u}))}return n}mergeValue({action:e,before:t,after:r}){return e===d.test||e===d.remove?t:r}compareResult(e){return e.action===d.test?{diffs:[],diff:e}:{diffs:[e],diff:e}}compareAny(e,t,r=new B,n=this._merged,a="value"){if(v(e)!==v(t))return n[a]=t,this.compareResult(V(r,e,t));switch(v(e)){case"object":return n[a]={},this.compareObjects(e,t,r,n[a]);case"array":return n[a]=[],this.compareArrays(e,t,r,n[a]);default:var s=("string"==typeof e?this.normalizeString(e)===this.normalizeString(t):e===t)?g(r,e):V(r,e,t);return n[a]=this.mergeValue(s),this.compareResult(s)}}compareObjects(t,r,n,e){const a={};if(b(t)&&b(r))return this.compareResult(g(n,t));var s=Object.keys(t);const i=new Set(Object.keys(r));for(const u of s){var o,c=[...i].find(e=>e===u||this.checkMatch(n,t,r,u,e));c&&c!==u&&(a[c]=this.compareResult(F(n,u,c))),void 0===c?(o=A(n.childPath(u),t[u]),e[u]=this.mergeValue(o),a[u]=this.compareResult(o)):(a[u]=this.compareAny(t[u],r[c],n.childPath(u),e,c),i.delete(c))}for(const d of i){var f=j(n.childPath(d),r[d]);e[d]=this.mergeValue(f),a[d]=this.compareResult(f)}return this.mergeResults(a,e)}compareArrays(t,r,n,e){if(0===t.length&&0===r.length)return this.compareResult(g(n,t));var a=this.getMatchFunc(n);if(!this.strictArrays&&!a)return this.compareEnums(t,r,n,e);const s={},i=new Set(r.keys());for(const u of t.keys()){var o,c=n.childPath(u),f=a?[...i].find(e=>this.checkMatch(n,t,r,u,e)):u;void 0===f||f>=r.length?(o=A(c,t[u]),e[u]=this.mergeValue(o),s[u]=this.compareResult(o)):(i.delete(f),s[u]=this.compareAny(t[u],r[f],c,e,u))}let u=t.length;for(const l of i){var d=j(n.childPath(u),r[l]);e[u]=this.mergeValue(d),s[u++]=this.compareResult(d)}return this.mergeResults(s,e,!0)}compareEnums(t,r,n,a){const s={},e=[],i=[],o=new Set,c=new Set;for(const y of t.keys()){let e=[];for(const b of r.keys())if(!o.has(b)){var f={},u=this.compareAny(t[y],r[b],n.childPath(y),f);if(!u.diffs.length){o.add(b),c.add(y),e={value:f.value,res:u};break}e[b]={value:f.value,res:u,diffs:typeof t[y]==typeof r[b]?u.diffs.length:-1}}i.push(e)}for(const y of t.keys()){const v=i[y];if(Array.isArray(v)){const O=[...Array(r.length).keys()].filter(e=>{return 0<=((null==(e=v[e])?void 0:e.diffs)||0)});var d,l=O.sort((e,t)=>{return((null==(e=v[e])?void 0:e.diffs)||0)-((null==(e=v[t])?void 0:e.diffs)||0)});for(const M of r.keys()){let e=l[M];if(!o.has(e)){for(const R of t.keys()){var h=i[R];if(Array.isArray(h)&&!c.has(R)&&h[e]<v[e]){e=-1;break}}if(0<=e){var{value:p,res:m}=v[e];a[y]=p,s[y]=m,c.add(y),o.add(e);break}}}c.has(y)||(d=A(n.childPath(y),t[y]),a[y]=this.mergeValue(d),s[y]=this.compareResult(d))}else e[y]=[],a[y]=v.value,s[y]=v.res}let y=t.length;for(var g of r.keys())o.has(g)||(g=j(n.childPath(y),r[g]),a[y]=this.mergeValue(g),s[y++]=this.compareResult(g));return this.mergeResults(s,a,!0)}}class se{constructor(e,t){this._engine=e,this._path=t}get before(){return this._engine.resolvePath("before",this._path)}get after(){var e=this._engine.getRenamedPath(this._path);return this._engine.resolvePath("after",e)}get up(){return(e=1)=>new se(this._engine,this._path.slice(0,-e))}get root(){return new se(this._engine,[])}}const ie=Symbol("renamed");class $ extends ae{constructor(e,t,r={}){super(e,t,r),this.before=e,this.after=t,this.beforeRefs=new Set,this.afterRefs=new Set,this.beforeCache=new Map,this.afterCache=new Map,this.compareCache=new Map,this.renamedPath={},this._formatMergeMeta=e=>Object.assign({type:e.type,action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.resolvePath=(e,t)=>{var r="before"===e?this.beforeCache:this.afterCache;let n=this[e];for(const s of t){var a=Array.isArray(n)?n[+s]:n[s];if(void 0===(n=void 0===a&&n.$ref?(n=R(n,this[e],r),Array.isArray(n)?n[+s]:n[s]):a))break}return n.$ref?R(n,this[e],r):n},this.rules="string"==typeof r.rules?this.getBaseRules(r.rules):r.rules||{},this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this),this.resolveUnchangedRefs=r.resolveUnchangedRefs||!1;var n=r.externalRefs||{};for(const a of Object.keys(n))this.beforeCache.set(a,n[a]),this.afterCache.set(a,n[a])}getMatchFunc(e){return z(this.rules,e,this.before)||super.getMatchFunc(e)}static apiDiff(e,t,r={}){return new $(e,t,r).compare()}static apiDiffTree(e,t,r={}){return new $(e,t,r).buildDiffTree()}static apiMerge(e,t,r={}){return new $(e,t,r).merge()}dereference(e,t,r){const n="#"+r.ref,[a,s]="before"===e?[this.beforeRefs,this.beforeCache]:[this.afterRefs,this.afterCache];r=()=>{t.$ref&&a.delete(t.$ref),a.delete(n)};return a.has(t.$ref)||"#"===t.$ref?[t,r]:(a.add(n),t.$ref&&a.add(t.$ref),[R(t,this[e],s),r])}getBaseRules(e){switch(e){case"OpenApi3":return ee;case"AsyncApi2":return Z;case"JsonSchema":return P()}}classifyDiff(e){const t=e;if("test"===e.action)return t;var r="rename"===e.action?[...e.path,"*",""]:[...e.path,""],r=N(this.rules,r,this.merged);const n=(Array.isArray(r)?r:l)["rename"===e.action?2:["add","remove","replace"].indexOf(e.action)];try{return t.type="function"==typeof n?n(new se(this,e.path)):n,t}catch(e){return t.type=s,t}}getRenamedPath(t){const r=[...t];let n=this.renamedPath;for(let e=0;e<t.length;e++){var a=t[e];if(void 0===n[a])break;(n=n[a])[ie]&&(r[e]=n[ie])}return r}compareResult(e){return e.action===d.rename&&Y(this.renamedPath,[...e.path,e.before,ie],e.after),super.compareResult(this.classifyDiff(e))}compareObjects(e,t,r,n){var a=e["$ref"],s=y(e,["$ref"]),i=t["$ref"],o=y(t,["$ref"]),c=a?a===i?a:a+":"+i:"#"+r.ref;const f=this.compareCache.get(c);if(f&&(b(s)&&b(o)||!a&&!i)){if(!f.result.diffs.length&&!this.resolveUnchangedRefs)return super.compareObjects(e,t,r,n);k(n,f.merged);var u=f.result.diffs.map(e=>Object.assign(Object.assign({},e),{path:[...r,...e.path]}));return Object.assign(Object.assign({},f.result),{diffs:u})}const[d,l]=this.dereference("before",e,r),[h,p]=this.dereference("after",t,r);u=Array.isArray(n)?[]:{};let m=super.compareObjects(d,h,r,n);return a&&i&&b(s)&&b(o)&&(s=m.diffs.map(e=>Object.assign(Object.assign({},e),{path:e.path.slice(r.items.length)})),this.compareCache.set(c,{result:Object.assign(Object.assign({},m),{diffs:s}),merged:n})),p(),l(),!a||a!==i||m.diffs.length||this.resolveUnchangedRefs?k(n,u):(Array.isArray(n)?n.length=0:Object.keys(n).forEach(e=>delete n[e]),m=super.compareObjects(e,t,r,n)),m}}const oe=$.apiDiff,ce=$.apiMerge,fe=$.apiDiffTree}]); | ||
/*! api-smart-diff@0.4.5 */ | ||
var ApiSmartDiff=function(r){var n={};function a(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.l=!0,t.exports}return a.m=r,a.c=n,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(I,e,t){"use strict";t.r(e),t.d(e,"messageTraitsRules",function(){return W}),t.d(e,"messageRules",function(){return X}),t.d(e,"asyncApi2Rules",function(){return Z}),t.d(e,"openapi3Rules",function(){return ee}),t.d(e,"jsonSchemaRules",function(){return P}),t.d(e,"serviceNodeRules",function(){return ne}),t.d(e,"DIFF_META_KEY",function(){return q}),t.d(e,"DiffAction",function(){return d}),t.d(e,"ClassifierType",function(){return r}),t.d(e,"breaking",function(){return n}),t.d(e,"nonBreaking",function(){return a}),t.d(e,"unclassified",function(){return s}),t.d(e,"annotation",function(){return i}),t.d(e,"allNonBreaking",function(){return o}),t.d(e,"allBreaking",function(){return c}),t.d(e,"onlyAddBreaking",function(){return f}),t.d(e,"addNonBreaking",function(){return u}),t.d(e,"allUnclassified",function(){return l}),t.d(e,"allAnnotation",function(){return h}),t.d(e,"PathPointer",function(){return B}),t.d(e,"breakingIf",function(){return p}),t.d(e,"breakingIfAfterTrue",function(){return m}),t.d(e,"added",function(){return j}),t.d(e,"removed",function(){return k}),t.d(e,"replaced",function(){return V}),t.d(e,"renamed",function(){return F}),t.d(e,"unchanged",function(){return g}),t.d(e,"isEmptyObject",function(){return b}),t.d(e,"typeOf",function(){return v}),t.d(e,"parsePath",function(){return K}),t.d(e,"buildPath",function(){return U}),t.d(e,"getPathRules",function(){return N}),t.d(e,"getPathMatchFunc",function(){return z}),t.d(e,"findExternalRefs",function(){return L}),t.d(e,"matchRule",function(){return O}),t.d(e,"objArray",function(){return M}),t.d(e,"resolveRef",function(){return R}),t.d(e,"getValueByPath",function(){return J}),t.d(e,"setValueByPath",function(){return Y}),t.d(e,"mergeValues",function(){return A}),t.d(e,"ApiCompare",function(){return $}),t.d(e,"JsonCompare",function(){return ae}),t.d(e,"apiDiff",function(){return oe}),t.d(e,"apiMerge",function(){return ce}),t.d(e,"apiDiffTree",function(){return fe});var d,r;function y(e,t){var r={};for(a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var n=0,a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]]);return r}const q="$diff",{breaking:n,nonBreaking:a,unclassified:s,annotation:i}=((t=d=d||{}).add="add",t.remove="remove",t.replace="replace",t.rename="rename",t.test="test",(e=r=r||{}).breaking="breaking",e.nonBreaking="non-breaking",e.annotation="annotation",e.unclassified="unclassified",r),o=[a,a,a],c=[n,n,n],f=[n,a,a],u=[a,n,n],l=[s,s,s],h=[i,i,i];class B{constructor(e,t){this.key=e,this.parent=t,this.items=[],void 0===e?this.escapedKey="":(this.escapedKey="string"==typeof e?e.replace(new RegExp("~1","g"),"/"):String(e),this.items=t?[...t.items,e]:[e])}get ref(){return this.parent?this.parent.ref+"/"+this.escapedKey:this.escapedKey}[Symbol.iterator](){let e=0;return{next:()=>({done:!(e<this.items.length),value:this.items[e++]})}}childPath(e){return new B(e,this)}}const p=e=>e?n:a,m=({after:e})=>p(e),j=(e,t)=>({path:e.items,after:t,action:d.add}),k=(e,t)=>({path:e.items,before:t,action:d.remove}),V=(e,t,r)=>({path:e.items,before:t,after:r,action:d.replace}),F=(e,t,r)=>({path:e.items,before:t,after:r,action:d.rename}),g=(e,t)=>({path:e.items,before:t,action:d.test}),b=e=>{for(const t in e)return!1;return!0},v=e=>Array.isArray(e)?"array":null==e?"null":typeof e,K=e=>{var[,...e]=e.split("/").map(e=>e.replace(new RegExp("~1","g"),"/"));return e},U=e=>"/"+e.map(e=>String(e).replace(new RegExp("/","g"),"~1")).join("/"),N=(e,t,r)=>{let n=e,a=r;for(var s of[...t]){if(a=void 0!==s&&void 0!==a?a[s]:void 0,n.hasOwnProperty("/"+s)&&"number"!=typeof s||(s="*"),!n.hasOwnProperty("/"+s))return;{const i=n["/"+s];if(Array.isArray(i))return i;n="function"==typeof i?i(a):i}}return n},z=(e,t,r)=>{e=N(e,t.items,r);return e&&!Array.isArray(e)?e["#"]:void 0},L=e=>{if("object"!=typeof e)return[];let t=new Set;if("array"===v(e))for(const n of e)"object"==typeof n&&(t=new Set([...t,...L(n)]));else for(const a of Object.keys(e)){var r;"$ref"===a?([r]=e[a].split("#"),r&&t.add(r)):"object"==typeof e[a]&&(t=new Set([...t,...L(e[a])]))}return[...t]},O=(e,t)=>(e["#"]=t,e),M=(r,e)=>O(e,({before:e,after:t})=>t.value[r]===e.value[r]),R=(e,t,r)=>{const n=e["$ref"],a=y(e,["$ref"]);if(n){var[s,i]=n.split("#");if(s&&!r.has(s))return e;r=J(s?r.get(s):t,K(i));return b(a)?r:A(r,a)}return e},J=(e,t)=>{let r=e;for(const n of t)if(void 0===(r="array"===v(r)?r[+n]:r[n]))break;return r},Y=(e,t,r,n=0)=>{var a;n>=t.length||("object"!=typeof e[a=t[n]]&&(e[a]={}),n===t.length-1?e[a]=r:Y(e[a],t,r,n+1))},A=(e,t)=>{if(Array.isArray(e))return Array.isArray(t)?e.push(...t):e;if("object"!=typeof e||"object"!=typeof t)return t;for(const r of Reflect.ownKeys(t))e[r]=A(e[r],t[r]);return e},x=[n,a,({before:e,after:t})=>p(t<e)],w=[n,a,({before:e,after:t})=>p(e<t)],G=[m,a,m],S=[m,a,m],H=[n,a,({before:e,after:t})=>p(!!(e%t))],Q=({after:e,up:t})=>{return void 0!==(null==(t=null==(t=null==(t=t(2).after)?void 0:t.properties)?void 0:t[e])?void 0:t.default)?a:n},P=(e=l)=>({"/":e,"/title":h,"/multipleOf":H,"/maximum":x,"/exclusiveMaximum":G,"/minimum":w,"/exclusiveMinimum":G,"/maxLength":x,"/minLength":w,"/pattern":[n,a,n],"/maxItems":x,"/minItems":w,"/uniqueItems":S,"/maxProperties":x,"/minProperties":w,"/required":{"/":f,"/*":[Q,a,Q]},"/enum":{"/":[n,a,n],"/*":[a,n,n]},"/type":[n,a,n],"/not":{"/":[n,a,n],"/*":()=>P(c)},"/allOf":{"/":[n,a,n],"/*":()=>P(c)},"/oneOf":{"/":[n,a,n],"/*":()=>P(u)},"/anyOf":{"/":[n,a,n],"/*":()=>P(u)},"/items":()=>P(u),"/properties":{"/":[n,a,n],"/*":()=>P(u)},"/additionalProperties":()=>P([n,n,m]),"/description":h,"/format":[n,a,n],"/default":[a,n,n],"/nullable":S,"/discriminator":{"/":l,"/propertyName":l,"/mapping":l},"/readOnly":S,"/writeOnly":S,"/example":h,"/examples":h,"/externalDocs":h,"/deprecated":S,"/xml":{"/":l,"/name":l,"/namespace":l,"/prefix":l,"/attribute":l,"/wrapped":l}});var t={"/":u,"/location":u,"/description":h},e={"/summary":h,"/tags":h,"/externalDocs":h,"/bindings":l},_=Object.assign({"/":u,"/*":u,"/operationId":u,"/description":h},e);const W=Object.assign({"/":u,"/*":u,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/examples":h},e),X=Object.assign({"/":c,"/headers":l,"/correlationId":t,"/schemaFormat":c,"/contentType":u,"/name":o,"/title":o,"/description":o,"/examples":h,"/traits":W,"/payload":P(c)},e);t=Object.assign({"/":u,"/operationId":u,"/description":h,"/traits":_,"/message":X},e),_={"/":u,"/version":u,"/termsOfService":u,"/license":{"/":u,"/name":c,"/url":f},"/title":h,"/description":h,"/contact":{"/":h,"/name":h,"/url":h,"/email":h}},e={"/":u,"/*":{"/":u,"/url":u,"/description":h,"/protocol":c,"/protocolVersion":c,"/variables":{"/":u,"/*":{"/":u,"/enum":{"/":u,"/*":u},"/default":c,"/description":h,"/examples":h}},"/security":{"/":c,"/*":c},"/bindings":l}},t={"/":u,"/description":o,"/bindings":l,"/subscribe":t,"/publish":t,"/parameters":{"/":c,"/*":{"/":u,"/description":o,"/schema":P(c),"/location":c}}};const Z={"/asyncapi":u,"/id":h,"/defaultContentType":c,"/info":_,"/servers":e,"/channels":{"/":u,"/*":t},"/components":o,"/tags":h,"/externalDocs":h};var _={"/":[a,n,n],"/*":{"/":[a,n,n],"/url":[a,n,n],"/description":h,"/variables":{"/":[a,n,n],"/*":{"/":[a,n,n],"/enum":{"/":[a,n,n],"/*":[a,n,n]},"/default":[n,n,n],"/description":h}}}},e={"/":[a,n,n],"/*":{"/":[a,n,n],"/name":[a,n,e=>{return"path"===(null==(e=e.up().before)?void 0:e.in)?a:n}],"/in":[a,n,n],"/schema":P(c),"/description":h,"/required":[n,a,m],"/deprecated":[n,a,m]}},t={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":h,"/required":[n,a,m],"/deprecated":[n,a,m]}},T={"/":[a,a,a],"/*":{"/contentType":[a,n,n],"/headers":t,"/style":[a,n,n],"/explode":[a,n,n],"/allowReserved":[a,n,n]}},T=(T={"/":[a,n,n],"/*":{"/":[a,n,s],"/schema":P(c),"/example":h,"/examples":h,"/encoding":T}},O(T,({before:e,after:t})=>{const[r=""]=String(t.key).split(";"),[n=""]=String(e.key).split(";");var[t,e]=r.split("/"),[a,s]=n.split("/");return(t===a||"*"===t||"*"===a)&&(e===s||"*"===e||"*"===s)})),C={"/":[a,n,n],"/description":h,"/content":T,"/required":[n,a,e=>e.after?n:a]},T={"/":[a,n,n],"/*":{"/":[a,n,n],"/description":h,"/headers":t,"/content":T}},D={"/":[n,a,s],"/*":[n,a,s]},E={"/":[a,n,n],"/tags":h,"/summary":h,"/description":h,"/externalDocs":h,"/operationId":[a,n,n],"/parameters":e,"/requestBody":C,"/responses":T,"/deprecated":[n,a,m],"/security":D,"/servers":_};const ee={"/openapi":[a,n,n],"/info":{"/":[a,n,n],"/title":h,"/description":h,"/termsOfService":h,"/contact":h,"/licence":{"/":[a,n,n],"/name":[n,n,n],"/url":[n,a,a]},"/version":h},"/servers":_,"/paths":(E={"/":[a,n,n],"/*":{"/":[a,n,a],"/summary":h,"/description":h,"/*":E,"/servers":_,"/parameters":e}},O(E,({before:e,after:t})=>{return String(e.key).replace(new RegExp("{.*?}","g"),"*")===String(t.key).replace(new RegExp("{.*?}","g"),"*")})),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)},"/responses":{"/":[a,n,n],"/*":T},"/parameters":{"/":[a,n,n],"/*":e},"/examples":h,"/requestBodies":{"/":[a,n,n],"/*":C},"/headers":t,"/securitySchemes":{"/":[n,a,n],"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":h,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":h,"/flows":[n,a,n],"/openIdConnectUrl":h}}},"/security":D,"/tags":h,"/externalDocs":h};_=e=>O(e,({before:{value:e},after:{value:t}})=>{var r;return t.type===e.type&&("model"===t.type?t.name===e.name:(null==(r=e.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))===(null==(r=t.data.path)?void 0:r.replace(new RegExp("{.*?}","g"),"*"))&&e.data.method===t.data.method)}),E={"/name":[a,n,n],"/style":l,"/description":h,"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]},T={"/":[a,n,n],"/*":E},e={"/":u,"/*":{"/":[a,n,n],"/mediaType":[a,n,n],"/schema":P(c),"/examples":M("key",{"/":h,"/*":h}),"/encodings":[a,n,n]}},C={"/path":M("name",T),"/query":M("name",{"/":[a,n,n],"/*":Object.assign(Object.assign({},E),{"/allowEmptyValue":[n,a,m],"/allowReserved":[n,a,m]})}),"/headers":M("name",T),"/cookie":M("name",T),"/body":{"/":[a,n,n],"/contents":M("mediaType",e),"/required":[n,a,m],"/description":h}},t={"/":l,"/*":{"/name":[a,n,n],"/style":l,"/description":h,"/explode":l,"/required":[n,a,m],"/deprecated":[n,a,m]}},D={"/":u,"/*":{"/":u,"/code":l,"/contents":M("mediaType",e),"/headers":M("name",t),"/description":h}},E={"/":[a,n,n],"/url":[a,n,n],"/name":h,"/description":h,"/variables":[a,n,n]},T={"/":[n,a,s],"/*":[n,a,s]};const te={"/":[a,n,n],"/data":()=>P(u),"/*":h},re={"/":[a,n,n],"/data":{"/id":h,"/iid":h,"/tags":h,"/summary":h,"/description":h,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/servers":{"/":l,"/*":E},"/callbacks":_({"/callbackName":h,"/method":[a,n,n],"/path":[a,n,n],"/request":C,"/responses":M("code",D),"/deprecated":l,"/internal":l,"/extensions":l}),"/security":T,"/deprecated":[n,a,m],"/internal":l,"/extensions":l},"/*":h};e={"/id":h,"/iid":h,"/tags":h,"/summary":h,"/description":h,"/name":h,"/version":h,"/servers":{"/":[a,n,n],"/*":E},"/security":T,"/securitySchemes":M("name",{"/":u,"/*":{"/":[n,a,n],"/type":[n,a,n],"/description":h,"/name":[n,a,n],"/in":[n,a,n],"/scheme":[n,a,n],"/bearerFormat":h,"/flows":[n,a,n],"/openIdConnectUrl":h}}),"/termsOfService":h,"/contact":h,"/license":[n,n,n],"/logo":h};const ne={"/*":h,"/data":e,"/children":_({"/":[a,n,n],"/*":({type:e})=>"model"===e?te:re}),"/components":{"/":[a,a,a],"/schemas":{"/":[a,n,n],"/*":P(u)}}};class ae{constructor(e,t,r={}){this.before=e,this.after=t,this._merged={},this._formatMergeMeta=e=>Object.assign({action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.trimStrings=r.trimStrings,this.caseSensitive=r.caseSensitive,this.strictArrays=r.strictArrays,this.matchRules=r.matchRules||{},this.diffKey=r.metaKey||q,this.arrayMeta=r.arrayMeta,this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this)}get merged(){return this._merged.value}setMeta(e,t,r){void 0===e[this.diffKey]&&(e[this.diffKey]={}),e[this.diffKey][t]=r}checkMatch(e,t,r,n,a){const s=this.getMatchFunc(e);return!!s&&s({path:e.items,before:{key:n,value:t[n],parent:t,source:this.before},after:{key:a,value:r[a],parent:r,source:this.after}})}getMatchFunc(e){e=e.ref;return this.matchRules[e]}compare(){return this.compareAny(this.before,this.after).diffs}buildDiffTree(){return this.compareAny(this.before,this.after).diffTree}merge(){return this.compareAny(this.before,this.after),this._merged.value}normalizeString(e){return e=this.trimStrings?e.trim():e,e=this.caseSensitive?e:e.toLowerCase()}mergeResults(e,t,r=!1){const n={diffs:[],diffTree:{}};for(var a of Object.keys(e)){var s,i,{diffs:o,diff:c,diffTree:f,parentMeta:u}=e[a];c&&c.action!==d.test?(i=c["path"],s=y(c,["path"]),i=i[i.length-1],this.setMeta(n.diffTree,i,s),n.diffs.push(c),r&&!this.arrayMeta?(void 0===n.parentMeta&&(n.parentMeta={}),n.parentMeta[i]=this.formatMergedMeta(c)):c.action===d.rename?this.setMeta(t,c.after,this.formatMergedMeta(c)):this.setMeta(t,i,this.formatMergedMeta(c)),a):(o.length&&(n.diffTree[a]=f,n.diffs.push(...o)),u&&this.setMeta(t,r?+a:a,{array:u}))}return n}mergeValue({action:e,before:t,after:r}){return e===d.test||e===d.remove?t:r}compareResult(e){return e.action===d.test?{diffs:[],diff:e}:{diffs:[e],diff:e}}compareAny(e,t,r=new B,n=this._merged,a="value"){if(v(e)!==v(t))return n[a]=t,this.compareResult(V(r,e,t));switch(v(e)){case"object":return n[a]={},this.compareObjects(e,t,r,n[a]);case"array":return n[a]=[],this.compareArrays(e,t,r,n[a]);default:var s=("string"==typeof e?this.normalizeString(e)===this.normalizeString(t):e===t)?g(r,e):V(r,e,t);return n[a]=this.mergeValue(s),this.compareResult(s)}}compareObjects(t,r,n,e){const a={};if(b(t)&&b(r))return this.compareResult(g(n,t));var s=Object.keys(t);const i=new Set(Object.keys(r));for(const u of s){var o,c=[...i].find(e=>e===u||this.checkMatch(n,t,r,u,e));c&&c!==u&&(a[c]=this.compareResult(F(n,u,c))),void 0===c?(o=k(n.childPath(u),t[u]),e[u]=this.mergeValue(o),a[u]=this.compareResult(o)):(a[u]=this.compareAny(t[u],r[c],n.childPath(u),e,c),i.delete(c))}for(const d of i){var f=j(n.childPath(d),r[d]);e[d]=this.mergeValue(f),a[d]=this.compareResult(f)}return this.mergeResults(a,e)}compareArrays(t,r,n,e){if(0===t.length&&0===r.length)return this.compareResult(g(n,t));var a=this.getMatchFunc(n);if(!this.strictArrays&&!a)return this.compareEnums(t,r,n,e);const s={},i=new Set(r.keys());for(const u of t.keys()){var o,c=n.childPath(u),f=a?[...i].find(e=>this.checkMatch(n,t,r,u,e)):u;void 0===f||f>=r.length?(o=k(c,t[u]),e[u]=this.mergeValue(o),s[u]=this.compareResult(o)):(i.delete(f),s[u]=this.compareAny(t[u],r[f],c,e,u))}let u=t.length;for(const l of i){var d=j(n.childPath(u),r[l]);e[u]=this.mergeValue(d),s[u++]=this.compareResult(d)}return this.mergeResults(s,e,!0)}compareEnums(t,r,n,a){const s={},e=[],i=[],o=new Set,c=new Set;for(const y of t.keys()){let e=[];for(const b of r.keys())if(!o.has(b)){var f={},u=this.compareAny(t[y],r[b],n.childPath(y),f);if(!u.diffs.length){o.add(b),c.add(y),e={value:f.value,res:u};break}e[b]={value:f.value,res:u,diffs:typeof t[y]==typeof r[b]?u.diffs.length:-1}}i.push(e)}for(const y of t.keys()){const v=i[y];if(Array.isArray(v)){const O=[...Array(r.length).keys()].filter(e=>{return 0<=((null==(e=v[e])?void 0:e.diffs)||0)});var d,l=O.sort((e,t)=>{return((null==(e=v[e])?void 0:e.diffs)||0)-((null==(e=v[t])?void 0:e.diffs)||0)});for(const M of r.keys()){let e=l[M];if(!o.has(e)){for(const R of t.keys()){var h=i[R];if(Array.isArray(h)&&!c.has(R)&&h[e]<v[e]){e=-1;break}}if(0<=e){var{value:p,res:m}=v[e];a[y]=p,s[y]=m,c.add(y),o.add(e);break}}}c.has(y)||(d=k(n.childPath(y),t[y]),a[y]=this.mergeValue(d),s[y]=this.compareResult(d))}else e[y]=[],a[y]=v.value,s[y]=v.res}let y=t.length;for(var g of r.keys())o.has(g)||(g=j(n.childPath(y),r[g]),a[y]=this.mergeValue(g),s[y++]=this.compareResult(g));return this.mergeResults(s,a,!0)}}class se{constructor(e,t){this._engine=e,this._path=t}get before(){return this._engine.resolvePath("before",this._path)}get after(){var e=this._engine.getRenamedPath(this._path);return this._engine.resolvePath("after",e)}get up(){return(e=1)=>new se(this._engine,this._path.slice(0,-e))}get root(){return new se(this._engine,[])}}const ie=Symbol("renamed");class $ extends ae{constructor(e,t,r={}){super(e,t,r),this.before=e,this.after=t,this.beforeRefs=new Set,this.afterRefs=new Set,this.beforeCache=new Map,this.afterCache=new Map,this.compareCache=new Map,this.renamedPath={},this._formatMergeMeta=e=>Object.assign({type:e.type,action:e.action},e.action===d.replace||e.action===d.rename?{replaced:e.before}:{}),this.resolvePath=(e,t)=>{var r="before"===e?this.beforeCache:this.afterCache;let n=this[e];for(const s of t){var a=Array.isArray(n)?n[+s]:n[s];if(void 0===(n=void 0===a&&n.$ref?(n=R(n,this[e],r),Array.isArray(n)?n[+s]:n[s]):a))break}return n.$ref?R(n,this[e],r):n},this.rules="string"==typeof r.rules?this.getBaseRules(r.rules):r.rules||{},this.formatMergedMeta=r.formatMergedMeta||this._formatMergeMeta.bind(this),this.resolveUnchangedRefs=r.resolveUnchangedRefs||!1;var n=r.externalRefs||{};for(const a of Object.keys(n))this.beforeCache.set(a,n[a]),this.afterCache.set(a,n[a])}getMatchFunc(e){return z(this.rules,e,this.before)||super.getMatchFunc(e)}static apiDiff(e,t,r={}){return new $(e,t,r).compare()}static apiDiffTree(e,t,r={}){return new $(e,t,r).buildDiffTree()}static apiMerge(e,t,r={}){return new $(e,t,r).merge()}dereference(e,t,r){const n="#"+r.ref,[a,s]="before"===e?[this.beforeRefs,this.beforeCache]:[this.afterRefs,this.afterCache];r=()=>{t.$ref&&a.delete(t.$ref),a.delete(n)};return a.has(t.$ref)||"#"===t.$ref?[t,r]:(a.add(n),t.$ref&&a.add(t.$ref),[R(t,this[e],s),r])}getBaseRules(e){switch(e){case"OpenApi3":return ee;case"AsyncApi2":return Z;case"JsonSchema":return P()}}classifyDiff(e){const t=e;if("test"===e.action)return t;var r="rename"===e.action?[...e.path,"*",""]:[...e.path,""],r=N(this.rules,r,this.merged);const n=(Array.isArray(r)?r:l)["rename"===e.action?2:["add","remove","replace"].indexOf(e.action)];try{return t.type="function"==typeof n?n(new se(this,e.path)):n,t}catch(e){return t.type=s,t}}getRenamedPath(t){const r=[...t];let n=this.renamedPath;for(let e=0;e<t.length;e++){var a=t[e];if(void 0===n[a])break;(n=n[a])[ie]&&(r[e]=n[ie])}return r}compareResult(e){return e.action===d.rename&&Y(this.renamedPath,[...e.path,e.before,ie],e.after),super.compareResult(this.classifyDiff(e))}compareObjects(e,t,r,n){var a=e["$ref"],s=y(e,["$ref"]),i=t["$ref"],o=y(t,["$ref"]),c=a?a===i?a:a+":"+i:"#"+r.ref;const f=this.compareCache.get(c);if(f&&(b(s)&&b(o)||!a&&!i)){if(!f.result.diffs.length&&!this.resolveUnchangedRefs)return super.compareObjects(e,t,r,n);A(n,f.merged);var u=f.result.diffs.map(e=>Object.assign(Object.assign({},e),{path:[...r,...e.path]}));return Object.assign(Object.assign({},f.result),{diffs:u})}const[d,l]=this.dereference("before",e,r),[h,p]=this.dereference("after",t,r);u=Array.isArray(n)?[]:{};let m=super.compareObjects(d,h,r,n);return a&&i&&b(s)&&b(o)&&(s=m.diffs.map(e=>Object.assign(Object.assign({},e),{path:e.path.slice(r.items.length)})),this.compareCache.set(c,{result:Object.assign(Object.assign({},m),{diffs:s}),merged:n})),p(),l(),!a||a!==i||m.diffs.length||this.resolveUnchangedRefs?A(n,u):(Array.isArray(n)?n.length=0:Object.keys(n).forEach(e=>delete n[e]),m=super.compareObjects(e,t,r,n)),m}}const oe=$.apiDiff,ce=$.apiMerge,fe=$.apiDiffTree}]); |
@@ -12,2 +12,15 @@ "use strict"; | ||
}); | ||
const contentMediaTypeRules = (rules) => (0, utils_1.matchRule)(rules, ({ before, after }) => { | ||
const [afterMediaType = ""] = String(after.key).split(";"); | ||
const [beforeMediaType = ""] = String(before.key).split(";"); | ||
const [afterType, afterSubType] = afterMediaType.split("/"); | ||
const [beforeType, beforeSubType] = beforeMediaType.split("/"); | ||
if (afterType !== beforeType && afterType !== "*" && beforeType !== "*") { | ||
return false; | ||
} | ||
if (afterSubType !== beforeSubType && afterSubType !== "*" && beforeSubType !== "*") { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
const serversRules = { | ||
@@ -39,2 +52,3 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/in": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/schema": (0, jsonschema_1.jsonSchemaRules)(constants_1.allBreaking), | ||
"/description": constants_1.allAnnotation, | ||
@@ -64,6 +78,6 @@ "/required": [constants_1.breaking, constants_1.nonBreaking, utils_1.breakingIfAfterTrue], | ||
}; | ||
const contentRules = { | ||
const contentRules = contentMediaTypeRules({ | ||
"/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/*": { | ||
"/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], | ||
"/": [constants_1.nonBreaking, constants_1.breaking, constants_1.unclassified], | ||
"/schema": (0, jsonschema_1.jsonSchemaRules)(constants_1.allBreaking), | ||
@@ -74,3 +88,3 @@ "/example": constants_1.allAnnotation, | ||
}, | ||
}; | ||
}); | ||
const requestBodiesRules = { | ||
@@ -77,0 +91,0 @@ "/": [constants_1.nonBreaking, constants_1.breaking, constants_1.breaking], |
@@ -9,2 +9,15 @@ import { breakingIfAfterTrue, matchRule } from "../utils"; | ||
}); | ||
const contentMediaTypeRules = (rules) => matchRule(rules, ({ before, after }) => { | ||
const [afterMediaType = ""] = String(after.key).split(";"); | ||
const [beforeMediaType = ""] = String(before.key).split(";"); | ||
const [afterType, afterSubType] = afterMediaType.split("/"); | ||
const [beforeType, beforeSubType] = beforeMediaType.split("/"); | ||
if (afterType !== beforeType && afterType !== "*" && beforeType !== "*") { | ||
return false; | ||
} | ||
if (afterSubType !== beforeSubType && afterSubType !== "*" && beforeSubType !== "*") { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
const serversRules = { | ||
@@ -36,2 +49,3 @@ "/": [nonBreaking, breaking, breaking], | ||
"/in": [nonBreaking, breaking, breaking], | ||
"/schema": jsonSchemaRules(allBreaking), | ||
"/description": allAnnotation, | ||
@@ -61,6 +75,6 @@ "/required": [breaking, nonBreaking, breakingIfAfterTrue], | ||
}; | ||
const contentRules = { | ||
const contentRules = contentMediaTypeRules({ | ||
"/": [nonBreaking, breaking, breaking], | ||
"/*": { | ||
"/": [nonBreaking, breaking, breaking], | ||
"/": [nonBreaking, breaking, unclassified], | ||
"/schema": jsonSchemaRules(allBreaking), | ||
@@ -71,3 +85,3 @@ "/example": allAnnotation, | ||
}, | ||
}; | ||
}); | ||
const requestBodiesRules = { | ||
@@ -74,0 +88,0 @@ "/": [nonBreaking, breaking, breaking], |
{ | ||
"name": "api-smart-diff", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Generate the diff between two API specifications (OpenAPI, AsyncAPI, JsonSchema)", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315046
4549