@@ -2,7 +2,7 @@ import { hasException } from './utils/exceptions.js';
22import { collectAdoption , collectException , collectAndReturnViolation } from './utils/collectionUtils.js' ;
33import { isCustomMethodIdentifier , getCustomMethodName , stripCustomMethodName } from './utils/resourceEvaluation.js' ;
44import { generateOperationID } from './utils/operationIdGeneration.js' ;
5- import { hasMethodWithVerbOverride , hasCustomMethodOverride } from './utils/extensions.js' ;
5+ import { hasMethodWithVerbOverride , hasCustomMethodOverride , VERB_OVERRIDE_EXTENSION } from './utils/extensions.js' ;
66
77const RULE_NAME = 'xgen-IPA-109-valid-operation-id' ;
88const ERROR_MESSAGE = 'Invalid OperationID.' ;
@@ -14,11 +14,12 @@ export default (input, _, { path }) => {
1414 return ;
1515 }
1616
17- let errors = [ ] ;
18- let expectedOperationID = '' ;
19- if ( isCustomMethodIdentifier ( resourcePath ) ) {
20- expectedOperationID = generateOperationID ( getCustomMethodName ( resourcePath ) , stripCustomMethodName ( resourcePath ) ) ;
17+ if ( hasException ( input , RULE_NAME ) ) {
18+ collectException ( input , RULE_NAME , path ) ;
19+ return ;
20+ }
2121
22+ if ( isCustomMethodIdentifier ( resourcePath ) ) {
2223 let obj ;
2324 if ( input . post ) {
2425 obj = input . post ;
@@ -28,12 +29,11 @@ export default (input, _, { path }) => {
2829 return ;
2930 }
3031
31- if ( hasException ( obj , RULE_NAME ) ) {
32- collectException ( obj , RULE_NAME , path ) ;
33- return ;
34- }
35-
3632 const operationId = obj . operationId ;
33+ const expectedOperationID = generateOperationID (
34+ getCustomMethodName ( resourcePath ) ,
35+ stripCustomMethodName ( resourcePath )
36+ ) ;
3737 if ( operationId !== expectedOperationID ) {
3838 const errors = [
3939 {
@@ -44,27 +44,27 @@ export default (input, _, { path }) => {
4444 return collectAndReturnViolation ( path , RULE_NAME , errors ) ;
4545 }
4646 } else if ( hasMethodWithVerbOverride ( input ) ) {
47- const methods = Object . keys ( input ) ;
48- for ( let i = 0 ; i < methods . length ; i ++ ) {
49- let obj = input [ methods [ i ] ] ;
50- const operationId = obj . operationId ;
51- if ( hasCustomMethodOverride ( obj ) ) {
52- expectedOperationID = generateOperationID ( obj [ 'x-xgen- method-verb-override' ] . verb , resourcePath ) ;
47+ const methods = Object . values ( input ) ;
48+ let errors = [ ] ;
49+ methods . forEach ( ( method ) => {
50+ if ( hasCustomMethodOverride ( method ) ) {
51+ const operationId = method . operationId ;
52+ const expectedOperationID = generateOperationID ( method [ VERB_OVERRIDE_EXTENSION ] . verb , resourcePath ) ;
5353 if ( operationId !== expectedOperationID ) {
5454 errors . push ( {
5555 path,
5656 message : `${ ERROR_MESSAGE } Found ${ operationId } , expected ${ expectedOperationID } .` ,
5757 } ) ;
5858 }
5959 }
60+ } ) ;
61+
62+ if ( errors . length !== 0 ) {
63+ return collectAndReturnViolation ( path , RULE_NAME , errors ) ;
6064 }
6165 } else {
6266 return ;
6367 }
6468
65- if ( errors . length !== 0 ) {
66- return collectAndReturnViolation ( path , RULE_NAME , errors ) ;
67- }
68-
6969 collectAdoption ( path , RULE_NAME ) ;
7070} ;
0 commit comments