@@ -74,6 +74,20 @@ import { encodingParamsCalculator } from './openapi3.description.encoding'
7474const documentAnnotationRule : CompareRules = { $ : allAnnotation }
7575const operationAnnotationRule : CompareRules = { $ : allAnnotation }
7676
77+ const openApiExtensionRulesFunction : ( fallbackRules : CompareRules | ( ( ) => CompareRules ) ) => CompareRules = ( fallbackRules ) => ( {
78+ '/*' : ( ctx ) => {
79+ const { key } = ctx
80+ return typeof key === 'string' && key . startsWith ( 'x-' )
81+ ? {
82+ $ : allUnclassified ,
83+ '/**' : {
84+ $ : allUnclassified ,
85+ } ,
86+ }
87+ : typeof fallbackRules === 'function' ? fallbackRules ( ) : fallbackRules
88+ } ,
89+ } )
90+
7791export const openApi3Rules = ( options : OpenApi3RulesOptions ) : CompareRules => {
7892 const requestSchemaRules = openApiSchemaRules ( options )
7993 const responseSchemaRules = openApiSchemaRules ( { ...options , response : true } )
@@ -331,6 +345,51 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
331345 } ,
332346 }
333347
348+ const operationCompareRules :CompareRules = {
349+ $ : [ nonBreaking , breaking , unclassified ] ,
350+ '/*' : operationAnnotationRule ,
351+ '/tags' : {
352+ ...operationAnnotationRule ,
353+ mapping : deepEqualsUniqueItemsArrayMappingResolver ,
354+ '/*' : {
355+ ...operationAnnotationRule ,
356+ [ IGNORE_DIFFERENCE_IN_KEYS_RULE ] : true ,
357+ } ,
358+ } ,
359+ '/parameters' : {
360+ ...parametersRules ,
361+ $ : [ nonBreaking , apihubParametersRemovalClassifyRule , breaking ] ,
362+ mapping : paramMappingResolver ( 2 ) ,
363+ } ,
364+ '/requestBody' : requestBodiesRules ,
365+ '/callbacks' : {
366+ '/*' : {
367+ //no support?
368+ } ,
369+ } ,
370+ '/responses' : responsesRules ,
371+ '/deprecated' : { $ : allDeprecated } ,
372+ '/security' : {
373+ $ : operationSecurityClassifyRule ,
374+ '/*' : {
375+ $ : operationSecurityItemClassifyRule ,
376+ '/*' : {
377+ $ : allBreaking ,
378+ mapping : deepEqualsUniqueItemsArrayMappingResolver ,
379+ '/*' : {
380+ $ : [ breaking , nonBreaking , breaking ] ,
381+ ignoreKeyDifference : true ,
382+ } ,
383+ } ,
384+ } ,
385+ } ,
386+ '/servers' : serversRules ,
387+ '/externalDocs' : {
388+ $ : allAnnotation ,
389+ '/*' : { $ : allAnnotation } ,
390+ } ,
391+ }
392+
334393 return {
335394 '/openapi' : documentAnnotationRule ,
336395 '/info' : {
@@ -346,50 +405,7 @@ export const openApi3Rules = (options: OpenApi3RulesOptions): CompareRules => {
346405 mapping : options . mode === COMPARE_MODE_OPERATION ? singleOperationPathMappingResolver : pathMappingResolver ,
347406 '/summary' : { $ : allAnnotation } ,
348407 '/description' : { $ : allAnnotation } ,
349- '/*' : {
350- $ : [ nonBreaking , breaking , unclassified ] ,
351- '/*' : operationAnnotationRule ,
352- '/tags' : {
353- ...operationAnnotationRule ,
354- mapping : deepEqualsUniqueItemsArrayMappingResolver ,
355- '/*' : {
356- ...operationAnnotationRule ,
357- [ IGNORE_DIFFERENCE_IN_KEYS_RULE ] : true ,
358- } ,
359- } ,
360- '/parameters' : {
361- ...parametersRules ,
362- $ : [ nonBreaking , apihubParametersRemovalClassifyRule , breaking ] ,
363- mapping : paramMappingResolver ( 2 ) ,
364- } ,
365- '/requestBody' : requestBodiesRules ,
366- '/callbacks' : {
367- '/*' : {
368- //no support?
369- } ,
370- } ,
371- '/responses' : responsesRules ,
372- '/deprecated' : { $ : allDeprecated } ,
373- '/security' : {
374- $ : operationSecurityClassifyRule ,
375- '/*' : {
376- $ : operationSecurityItemClassifyRule ,
377- '/*' : {
378- $ : allBreaking ,
379- mapping : deepEqualsUniqueItemsArrayMappingResolver ,
380- '/*' : {
381- $ : [ breaking , nonBreaking , breaking ] ,
382- ignoreKeyDifference : true ,
383- } ,
384- } ,
385- } ,
386- } ,
387- '/servers' : serversRules ,
388- '/externalDocs' : {
389- $ : allAnnotation ,
390- '/*' : { $ : allAnnotation } ,
391- } ,
392- } ,
408+ ...openApiExtensionRulesFunction ( operationCompareRules ) ,
393409 '/servers' : serversRules ,
394410 '/parameters' : {
395411 ...parametersRules ,
0 commit comments