Skip to content

Commit 5b191b2

Browse files
address the comments
1 parent 2afb4c9 commit 5b191b2

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

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'
Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
import { isCustomMethod } from './utils/resourceEvaluation.js';
22

33
const ERROR_MESSAGE = 'The HTTP method for custom methods must be GET or POST.';
4+
const ERROR_RESULT = [{ message: ERROR_MESSAGE }];
45
const VALID_METHODS = ['get', 'post'];
56

6-
export default (paths) => {
7-
// Collect all errors
8-
const errors = [];
7+
export default (input, opts, { path }) => {
8+
// Extract the path key (e.g., '/a/{exampleId}:method') from the JSONPath.
9+
let pathKey = path[1];
910

10-
// Iterate through each path key and its corresponding path item
11-
for (const [pathKey, pathItem] of Object.entries(paths)) {
12-
// Skip if not a custom method
13-
if (!isCustomMethod(pathKey)) continue;
11+
if (!isCustomMethod(pathKey)) return;
1412

15-
// Get HTTP methods for this path
16-
const httpMethods = Object.keys(pathItem);
13+
const httpMethods = Object.keys(input);
1714

18-
// Check for invalid methods
19-
if (httpMethods.some((method) => !VALID_METHODS.includes(method))) {
20-
errors.push({ path: ['paths', pathKey], message: ERROR_MESSAGE });
21-
continue;
22-
}
15+
// Check for invalid methods
16+
if (httpMethods.some((method) => !VALID_METHODS.includes(method))) {
17+
return ERROR_RESULT;
18+
}
2319

24-
// Check for multiple valid methods
25-
const validMethodCount = httpMethods.filter((method) => VALID_METHODS.includes(method)).length;
20+
// Check for multiple valid methods
21+
const validMethodCount = httpMethods.filter((method) => VALID_METHODS.includes(method)).length;
2622

27-
if (validMethodCount > 1) {
28-
errors.push({ path: ['paths', pathKey], message: ERROR_MESSAGE });
29-
}
23+
if (validMethodCount > 1) {
24+
return ERROR_RESULT;
3025
}
31-
32-
return errors;
3326
};

0 commit comments

Comments
 (0)