@@ -14,9 +14,23 @@ import {
1414  SPEC_TYPE_OPEN_API_30 , 
1515  SPEC_TYPE_OPEN_API_31 , 
1616  SpecType , 
17+   OpenApiSpecVersion , 
1718}  from  '@netcracker/qubership-apihub-api-unifier' 
1819import  {  DEFAULT_NORMALIZED_RESULT ,  DEFAULT_OPTION_DEFAULTS_META_KEY ,  DEFAULT_OPTION_ORIGINS_META_KEY ,  DIFF_META_KEY  }  from  './core' 
1920
21+ function  isOpenApiSpecVersion ( specType : SpecType ) : specType  is OpenApiSpecVersion  { 
22+   return  specType  ===  SPEC_TYPE_OPEN_API_30  ||  specType  ===  SPEC_TYPE_OPEN_API_31 
23+ } 
24+ 
25+ function  areSpecTypesCompatible ( beforeType : SpecType ,  afterType : SpecType ) : boolean  { 
26+   if  ( beforeType  ===  afterType )  { 
27+     return  true 
28+   } 
29+   
30+   // Allow comparison between different OpenAPI versions 
31+   return  isOpenApiSpecVersion ( beforeType )  &&  isOpenApiSpecVersion ( afterType ) 
32+ } 
33+ 
2034export  const  COMPARE_ENGINES_MAP : Record < SpecType ,  CompareEngine >  =  { 
2135  [ SPEC_TYPE_JSON_SCHEMA_04 ] : compareJsonSchema ( SPEC_TYPE_JSON_SCHEMA_04 ) , 
2236  [ SPEC_TYPE_JSON_SCHEMA_06 ] : compareJsonSchema ( SPEC_TYPE_JSON_SCHEMA_06 ) , 
@@ -31,7 +45,7 @@ export const COMPARE_ENGINES_MAP: Record<SpecType, CompareEngine> = {
3145export  function  apiDiff ( before : unknown ,  after : unknown ,  options : CompareOptions  =  { } ) : CompareResult  { 
3246  const  beforeSpec  =  resolveSpec ( before ) 
3347  const  afterSpec  =  resolveSpec ( after ) 
34-   if  ( beforeSpec . type   !==   afterSpec . type )  { 
48+   if  ( ! areSpecTypesCompatible ( beforeSpec . type ,   afterSpec . type ) )  { 
3549    throw  new  Error ( `Specification cannot be different. Got ${ beforeSpec . type }   and ${ afterSpec . type }  ` ) 
3650  } 
3751  const  engine  =  COMPARE_ENGINES_MAP [ beforeSpec . type ] 
0 commit comments