@@ -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 { hasVerbOverride } from './utils/extensions.js' ;
5+ import { hasMethodWithVerbOverride , isLegacyCustomMethod } from './utils/extensions.js' ;
66
77const RULE_NAME = 'xgen-IPA-109-valid-operation-id' ;
88const ERROR_MESSAGE = 'Invalid OperationID.' ;
@@ -14,44 +14,54 @@ export default (input, _, { path }) => {
1414 return ;
1515 }
1616
17+ let errors = [ ] ;
1718 let expectedOperationID = '' ;
1819 if ( isCustomMethodIdentifier ( resourcePath ) ) {
1920 expectedOperationID = generateOperationID ( getCustomMethodName ( resourcePath ) , stripCustomMethodName ( resourcePath ) ) ;
20- } else if ( hasVerbOverride ( input ) ) {
2121
22+ let obj ;
23+ if ( input . post ) {
24+ obj = input . post ;
25+ } else if ( input . get ) {
26+ obj = input . get ;
27+ } else {
28+ return ;
29+ }
2230
23- //const ext = input['x-xgen-method-verb-override'];
24- //expectedOperationID = generateOperationID(ext.verb, resourcePath);
25- }
31+ if ( hasException ( obj , RULE_NAME ) ) {
32+ collectException ( obj , RULE_NAME , path ) ;
33+ return ;
34+ }
2635
27- let obj ;
28- if ( input . post ) {
29- obj = input . post ;
30- } else if ( input . get ) {
31- obj = input . get ;
32- } else if ( input . delete ) {
33- obj = input . delete ;
34- console . log ( "yes" ) ;
36+ const operationId = obj . operationId ;
37+ errors . push ( checkViolationAndReturnError ( operationId , expectedOperationID , path ) ) ;
38+ } else if ( hasMethodWithVerbOverride ( input ) ) {
39+ const methods = Object . keys ( input ) ;
40+ for ( let i = 0 ; i < methods . length ; i ++ ) {
41+ let obj = input [ methods [ i ] ] ;
42+ const operationId = obj . operationId ;
43+ if ( isLegacyCustomMethod ( obj ) ) {
44+ expectedOperationID = generateOperationID ( obj [ 'x-xgen-method-verb-override' ] . verb , resourcePath ) ;
45+ errors . push ( checkViolationAndReturnError ( operationId , expectedOperationID , path ) ) ;
46+ }
47+ }
3548 } else {
36- console . log ( 'AHHHHH' , input ) ;
37- return ;
38- }
39-
40- if ( hasException ( obj , RULE_NAME ) ) {
41- collectException ( obj , RULE_NAME , path ) ;
4249 return ;
4350 }
4451
45- const operationId = obj . operationId ;
46- if ( expectedOperationID !== operationId ) {
47- const errors = [
48- {
49- path,
50- message : `${ ERROR_MESSAGE } Found ${ operationId } , expected ${ expectedOperationID } .` ,
51- } ,
52- ] ;
52+ if ( errors . length !== 0 ) {
5353 return collectAndReturnViolation ( path , RULE_NAME , errors ) ;
5454 }
5555
5656 collectAdoption ( path , RULE_NAME ) ;
5757} ;
58+
59+ function checkViolationAndReturnError ( oldOperationID , newOperationID , path ) {
60+ if ( oldOperationID !== newOperationID ) {
61+ return {
62+ path,
63+ message : `${ ERROR_MESSAGE } Found ${ oldOperationID } , expected ${ newOperationID } .` ,
64+ } ;
65+ }
66+ return ;
67+ }
0 commit comments