|
| 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