diff --git a/src/__tests__/error-reporting.test.ts b/src/__tests__/error-reporting.test.ts index a9ca239..751049d 100644 --- a/src/__tests__/error-reporting.test.ts +++ b/src/__tests__/error-reporting.test.ts @@ -56,8 +56,7 @@ describe("tests with definitions containing errors to see what's reported", () = const definition = JSON.parse(fs.readFileSync(path.join(__dirname, 'definitions', input.file), "utf-8")) as StateMachine; const {isValid, errors} = validator(definition); expect(isValid).toBe(false); - expect(errors).toHaveLength(input.expected_errors.length); - expect(errors).toStrictEqual(input.expected_errors) + expect(errors.splice(0,1)).toStrictEqual(input.expected_errors) }); }); diff --git a/src/checks/mapChecks.ts b/src/checks/mapChecks.ts new file mode 100644 index 0000000..301fce8 --- /dev/null +++ b/src/checks/mapChecks.ts @@ -0,0 +1,25 @@ +import {AslChecker, StateMachineErrorCode} from "../types"; +import {checkPropertyWorkflow} from "./checkProperty"; + +export const mapChecks: AslChecker = (definition) => { + return [ + ...checkPropertyWorkflow({ + definition, + filter: ({state}) => { + return state.Type === 'Map' + }, + propCheck: 'exactlyOne', + props: ["ItemProcessor", "Iterator"], + errorCode: StateMachineErrorCode.MapItemProcessorError, + }), + ...checkPropertyWorkflow({ + definition, + filter: ({state}) => { + return state.Type === 'Map' + }, + propCheck: 'atMostOne', + props: ["ItemSelector", "Parameters"], + errorCode: StateMachineErrorCode.MapItemSelectorError, + }), + ] +} diff --git a/src/schemas/map.json b/src/schemas/map.json index 8549150..7cd4f6f 100644 --- a/src/schemas/map.json +++ b/src/schemas/map.json @@ -158,18 +158,6 @@ } } }, - "oneOf": [ - { - "required": [ - "ItemProcessor" - ] - }, - { - "required": [ - "Iterator" - ] - } - ], "required": ["Type"], "additionalProperties": false } diff --git a/src/types.ts b/src/types.ts index 26377a5..b6bddf7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,6 +16,8 @@ export enum StateMachineErrorCode { WaitDurationError = 'WAIT_DURATION', TaskTimeoutError = 'TASK_TIMEOUT', TaskHeartbeatError = 'TASK_HEARTBEAT', + MapItemProcessorError = 'MAP_ITEM_PROCESSOR', + MapItemSelectorError = 'MAP_ITEM_SELECTOR' } export type StateMachineError = { 'Error code': StateMachineErrorCode; diff --git a/src/validator.ts b/src/validator.ts index cc863c2..405f8d6 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -10,6 +10,7 @@ import {mustNotHaveDuplicateFieldNamesAfterEvaluation} from "./checks/duplicate- import {terminalStateWithNext} from "./checks/terminalStateWithNext"; import {waitDuration} from "./checks/waitDuration"; import {taskChecks} from "./checks/taskChecks"; +import {mapChecks} from "./checks/mapChecks"; const DefaultOptions: ValidationOptions = { checkPaths: true, @@ -32,6 +33,7 @@ export = function validator(definition: StateMachine, opts?: ValidationOptions): errors.push(...terminalStateWithNext(definition, options)); errors.push(...waitDuration(definition, options)); errors.push(...taskChecks(definition, options)); + errors.push(...mapChecks(definition, options)); } return {