Skip to content

Commit 45b238f

Browse files
Create method checks should apply resource collection URIs
1 parent bd60a15 commit 45b238f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
1+
import {
2+
getResourcePathItems,
3+
isCustomMethodIdentifier, isResourceCollectionIdentifier, isSingletonResource,
4+
} from './utils/resourceEvaluation.js';
25
import { hasException } from './utils/exceptions.js';
36
import {
47
collectAdoption,
@@ -11,11 +14,13 @@ const RULE_NAME = 'xgen-IPA-106-create-method-response-code-is-201';
1114
const ERROR_MESSAGE =
1215
'The Create method must return a 201 Created response. This method either lacks a 201 Created response or defines a different 2xx status code.';
1316

14-
export default (input, _, { path }) => {
17+
export default (input, _, { path, documentInventory }) => {
18+
const oas = documentInventory.resolved;
1519
const resourcePath = path[1];
20+
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
1621

17-
// Skip custom methods
18-
if (isCustomMethodIdentifier(resourcePath)) {
22+
const isResourceCollection = isResourceCollectionIdentifier(resourcePath) && !isSingletonResource(resourcePaths);
23+
if (isCustomMethodIdentifier(resourcePath) || !isResourceCollection) {
1924
return;
2025
}
2126

0 commit comments

Comments
 (0)