Skip to content

Commit 439edfc

Browse files
address the comments
1 parent 5b191b2 commit 439edfc

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

tools/spectral/ipa/__tests__/eachCustomMethodMustBeGetOrPost.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ testRule('xgen-IPA-109-custom-method-must-be-GET-or-POST', [
1818
'/b:method': {
1919
get: {},
2020
},
21+
'/c/{exampleId}:method': {
22+
get: {},
23+
'x-xgen-IPA-exception': {}
24+
},
25+
'/c:method': {
26+
get: {},
27+
'x-xgen-IPA-exception': {}
28+
},
2129
},
2230
},
2331
errors: [],

tools/spectral/ipa/rulesets/IPA-109.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ rules:
99
description: 'The HTTP method for custom methods must be GET or POST. http://go/ipa/109'
1010
message: '{{error}} http://go/ipa/109'
1111
severity: warn
12-
given: '$.paths[*]'
12+
given: "$.paths[*]"
1313
then:
1414
function: 'eachCustomMethodMustBeGetOrPost'

tools/spectral/ipa/rulesets/functions/eachCustomMethodMustBeGetOrPost.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { isCustomMethod } from './utils/resourceEvaluation.js';
33
const ERROR_MESSAGE = 'The HTTP method for custom methods must be GET or POST.';
44
const ERROR_RESULT = [{ message: ERROR_MESSAGE }];
55
const VALID_METHODS = ['get', 'post'];
6+
const EXCEPTION_EXTENSION_KEY = 'x-xgen-IPA-exception';
67

78
export default (input, opts, { path }) => {
89
// Extract the path key (e.g., '/a/{exampleId}:method') from the JSONPath.
910
let pathKey = path[1];
1011

1112
if (!isCustomMethod(pathKey)) return;
1213

13-
const httpMethods = Object.keys(input);
14+
//Exclude exception extension key
15+
let keys = Object.keys(input);
16+
const httpMethods = keys.filter(key => key !== EXCEPTION_EXTENSION_KEY);
1417

1518
// Check for invalid methods
1619
if (httpMethods.some((method) => !VALID_METHODS.includes(method))) {

0 commit comments

Comments
 (0)