Repository: ChristopheBougere/asl-validator (ts)

Issue:
choice schema's Variable type should be a reference path, not a string
**Describe the bug**
The validator fails to emit an error for the Variable expression when it's not a reference path. It looks like this is due to the schema type being `string` and not the type we have to trigger the asl-path-validator code.


**To Reproduce**
I can do a PR for this with a full example but here's a snippet:

```json
            "Choices": [
              {
                "Variable": "States.ArrayContains($.clients.unique, 'null')",
                "BooleanEquals": true,
                "Next": "Use Array Length Minus One"
              }
            ],
```

**Expected behavior**
Report an error that the `Variable` field must be a valid reference path.  The expression provided in this example is an intrinsic function but that's not available in this context. It must be a reference path.

**Version:**
3.x




Pull request description:
fix: set choice state variable and path fields set to reference paths
This was a miss when I added the validation for the path expressions. 

From the [spec](https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html) for the Choice state: 

>The values of Variable and Path fields in a comparison must be valid [Reference Paths](https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-paths.html#amazon-states-language-reference-paths).

Small change to update the schema and provide a test for the negative case.

closes #144 

Patch:
diff --git a/src/schemas/choice.json b/src/schemas/choice.json
index 8983953..b8b8f3a 100644
--- a/src/schemas/choice.json
+++ b/src/schemas/choice.json
@@ -6,7 +6,7 @@
       "type": "object",
       "properties": {
         "Variable": {
-          "type": "string"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "And": {
           "type": "array",
@@ -33,7 +33,7 @@
           "type": "boolean"
         },
         "BooleanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "IsBoolean": {
           "type": "boolean"
@@ -42,31 +42,31 @@
           "type": "number"
         },
         "NumericEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "NumericGreaterThan": {
           "type": "number"
         },
         "NumericGreaterThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "NumericGreaterThanEquals": {
           "type": "number"
         },
         "NumericGreaterThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "NumericLessThan": {
           "type": "number"
         },
         "NumericLessThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "NumericLessThanEquals": {
           "type": "number"
         },
         "NumericLessThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "IsNumeric": {
           "type": "boolean"
@@ -75,31 +75,31 @@
           "type": "string"
         },
         "StringEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "StringGreaterThan": {
           "type": "string"
         },
         "StringGreaterThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "StringGreaterThanEquals": {
           "type": "string"
         },
         "StringGreaterThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "StringLessThan": {
           "type": "string"
         },
         "StringLessThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "StringLessThanEquals": {
           "type": "string"
         },
         "StringLessThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "StringMatches": {
           "type": "string"
@@ -111,31 +111,31 @@
           "type": "string"
         },
         "TimestampEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "TimestampGreaterThan": {
           "type": "string"
         },
         "TimestampGreaterThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "TimestampGreaterThanEquals": {
           "type": "string"
         },
         "TimestampGreaterThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "TimestampLessThan": {
           "type": "string"
         },
         "TimestampLessThanPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "TimestampLessThanEquals": {
           "type": "string"
         },
         "TimestampLessThanEqualsPath": {
-          "$ref": "paths.json#/definitions/asl_path"
+          "$ref": "paths.json#/definitions/asl_ref_path"
         },
         "IsTimestamp": {
           "type": "boolean"


Test patch:
diff --git a/src/__tests__/definitions/invalid-choice-state-variable.json b/src/__tests__/definitions/invalid-choice-state-variable.json
new file mode 100644
index 0000000..95a3cae
--- /dev/null
+++ b/src/__tests__/definitions/invalid-choice-state-variable.json
@@ -0,0 +1,27 @@
+{
+  "Comment": "Violates the rule: The values of Variable and Path fields in a comparison must be valid Reference Paths.",
+  "StartAt": "ChoiceState",
+  "States": {
+    "ChoiceState": {
+      "Type": "Choice",
+      "Choices": [
+        {
+          "Variable": "States.ArrayContains($.clients.unique, 'null')",
+          "NumericEquals": 1,
+          "Next": "FirstMatchState"
+        }
+      ],
+      "Default": "DefaultState"
+    },
+
+    "FirstMatchState": {
+      "Type": "Pass",
+      "End": true
+    },
+
+    "DefaultState": {
+      "Type": "Pass",
+      "End": true
+    }
+  }
+}