Repository: ChristopheBougere/asl-validator (ts)

Issue:
Map ItemProcessor schema fails to validate unless ProcessorConfig is present
**Describe the bug**
Map's ItemProcessor schema fails to validate unless ProcessorConfig is present, despite this field being optional (spec references below); when not present inline mode is used. The issue is caused by the requirement that the schema match `oneOf` the subschemas at https://github.com/ChristopheBougere/asl-validator/blob/main/src/schemas/map.json#L75.

**To Reproduce**
```json
{
  "StartAt": "Do Things",
  "States": {
    "Do Things": {
      "Type": "Map",
      "ItemProcessor": {
        "StartAt": "Run",
        "States": {
          "Run": {
            "Type": "Pass",
            "Result": {
              "ok": true
            },
            "End": true
          }
        }
      },
      "End": true
    }
  }
}
```

**Expected behavior**
The schema to successfully validate.

**Version:** 3.6.1

**Additional context**
Ref: https://states-language.net/#map-item-processor

>  The "ItemProcessor" field MAY contain a field named "ProcessorConfig", whose value MUST be a JSON object whose value is defined by the interpreter. The interpreter will execute the ItemProcessor according to the ProcessorConfig. 

Ref: https://docs.aws.amazon.com/step-functions/latest/dg/concepts-asl-use-map-state-inline.html#map-state-inline-additional-fields

> `ProcessorConfig` – An optional JSON object that specifies the processing mode for the Map state. This object contains the Mode sub-field. This field defaults to INLINE, which uses the Map state in Inline mode.


Pull request:
fix: semantics for item processor
This closes #135 

I added a test to recreate the failure and then modified the map's schema. The previous definition looked ok but evidently resulted in the field being required.

This change moves the `oneOf` into the ProcessorConfig definition (still not a required field). The options for the `oneOf` enumerate the two valid configs defined by AWS

Patch:
diff --git a/src/schemas/map.json b/src/schemas/map.json
index f7a3965..8369600 100644
--- a/src/schemas/map.json
+++ b/src/schemas/map.json
@@ -72,24 +72,21 @@
     "ItemProcessor": {
       "type": "object",
       "allOf": [{ "$ref": "base-state-machine.json#" }],
-      "oneOf": [
-        {
-          "properties": {
-            "ProcessorConfig": {
-              "type": "object",
+      "$comment": "The \"ItemProcessor\" field MAY contain a field named \"ProcessorConfig\", whose value MUST be a JSON object whose value is defined by the interpreter.",
+      "properties": {
+        "ProcessorConfig": {
+          "type": "object",
+          "oneOf": [
+            {
               "properties": {
                 "Mode": {
                   "type": "string",
                   "enum": ["INLINE"]
                 }
-              }
-            }
-          }
-        },
-        {
-          "properties": {
-            "ProcessorConfig": {
-              "type": "object",
+              },
+              "required": ["Mode"]
+            },
+            {
               "properties": {
                 "Mode": {
                   "type": "string",
@@ -99,11 +96,12 @@
                   "type": "string",
                   "enum": ["EXPRESS", "STANDARD"]
                 }
-              }
+              },
+              "required": ["Mode", "ExecutionType"]
             }
-          }
+          ]
         }
-      ]
+      }
     },
     "Iterator": {
       "$ref": "base-state-machine.json#"


Test patch:
diff --git a/src/__tests__/definitions/valid-map-noconfig.asl.json b/src/__tests__/definitions/valid-map-noconfig.asl.json
new file mode 100644
index 0000000..856d004
--- /dev/null
+++ b/src/__tests__/definitions/valid-map-noconfig.asl.json
@@ -0,0 +1,45 @@
+{
+  "Comment": "Valid example of Map without ProcessorConfig",
+  "StartAt": "Map",
+  "States": {
+    "Map": {
+      "Type": "Map",
+      "ItemReader": {
+        "ReaderConfig": {
+          "InputType": "CSV",
+          "CSVHeaderLocation": "FIRST_ROW",
+          "MaxItems": 1
+        },
+        "Resource": "arn:aws:states:::s3:getObject",
+        "Parameters": {
+          "Bucket": "Database",
+          "Key": "csv-dataset/ratings.csv"
+        }
+      },
+      "ItemProcessor": {
+        "StartAt": "LambdaTask",
+        "States": {
+          "LambdaTask": {
+            "Type": "Task",
+            "Resource": "arn:aws:states:::lambda:invoke",
+            "OutputPath": "$.Payload",
+            "Parameters": {
+              "Payload.$": "$",
+              "FunctionName": "arn:aws:lambda:us-east-2:123456789012:function:processCSVData"
+            },
+            "End": true
+          }
+        }
+      },
+      "Label": "Map",
+      "End": true,
+      "ResultWriter": {
+        "Resource": "arn:aws:states:::s3:putObject",
+        "Parameters": {
+          "Bucket": "myOutputBucket",
+          "Prefix": "csvProcessJobs"
+        }
+      }
+    }
+  }
+}