Skip to content

Commit 53692d8

Browse files
author
Sophia Marie Terry
committed
CLOUDP-328959: Implemented basic Operation ID Validation for update operations
1 parent f6ff5dd commit 53692d8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { hasException } from './utils/exceptions.js';
2+
import { collectAdoption, collectAndReturnViolation } from './utils/collectionUtils.js';
3+
import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js';
4+
import { generateOperationID } from './utils/operationIdGeneration.js';
5+
6+
const RULE_NAME = 'xgen-IPA-107-valid-operation-id';
7+
const ERROR_MESSAGE = 'Invalid OperationID';
8+
9+
export default (input, _, { path, documentInventory }) => {
10+
let resourcePath = path[1];
11+
const oas = documentInventory.resolved;
12+
let methodName = 'update';
13+
14+
// TODO detect exceptions
15+
16+
if (isCustomMethodIdentifier(resourcePath)) {
17+
methodName = getCustomMethodName(resourcePath);
18+
resourcePath = stripCustomMethodName(resourcePath);
19+
}
20+
21+
let errors = [];
22+
const expectedOperationID = generateOperationID(methodName, resourcePath);
23+
if (expectedOperationID != input.operationId) {
24+
errors.push({
25+
path: path,
26+
message: `${ERROR_MESSAGE} Found ${input.operationId} expected ${expectedOperationID}.`,
27+
});
28+
}
29+
30+
if (errors.length !== 0) {
31+
return collectAndReturnViolation(path, RULE_NAME, errors);
32+
}
33+
collectAdoption(path, RULE_NAME);
34+
};

0 commit comments

Comments
 (0)