ChristopheBougere / asl-validator

A simple Amazon States Language validator based on JSON schemas.
Apache License 2.0
106 stars 28 forks source link

Parameter is valid but asl-validator returns a SCHEMA_VALIDATION_FAILED error #150

Closed burck1 closed 3 months ago

burck1 commented 3 months ago

Describe the bug

asl-validator returns a SCHEMA_VALIDATION_FAILED error when it is not expected.

$ npx asl-validator --json-path test.asl.json
✕ State machine definition "test.asl.json" is invalid:
 SCHEMA_VALIDATION_FAILED: /States/Get Record Outputs/Parameters/FooBar.$ is invalid. must match format "asl_payload_template"

To Reproduce

State machine definition:

{
  "StartAt": "Mock Service Catalog Describe Record",
  "States": {
    "Mock Service Catalog Describe Record": {
      "Type": "Pass",
      "Parameters": {
        "DescribeRecord": {
          "RecordDetail": {
            "RecordId": "rec-abcdefghijklm",
            "Status": "SUCCEEDED",
            "COMMENT": "there are more properties, limited for brevity"
          },
          "RecordOutputs": [
            {
              "Description": "Foo Bar",
              "OutputKey": "FooBar",
              "OutputValue": "0123456789"
            },
            {
              "Description": "Fizz Buzz",
              "OutputKey": "FizzBuzz",
              "OutputValue": "fizzbuzz@example.com"
            }
          ]
        }
      },
      "ResultPath": "$",
      "Next": "Get Record Outputs"
    },
    "Get Record Outputs": {
      "Type": "Pass",
      "Parameters": {
        "FooBar.$": "States.ArrayGetItem($.DescribeRecord.RecordOutputs[?(@.OutputKey == FooBar)].OutputValue, 0)",
        "FizzBuzz.$": "States.ArrayGetItem($.DescribeRecord.RecordOutputs[?(@.OutputKey == FizzBuzz)].OutputValue, 0)"
      },
      "ResultPath": "$",
      "End": true
    }
  }
}

Example Execution: image

Expected behavior The syntax for the Get Record Outputs > Parameters in the provided example is valid. asl-validator should not return a SCHEMA_VALIDATION_FAILED error.

Version:

$ npx asl-validator --version                
3.8.2

Additional context

The Mock Service Catalog Describe Record pass state in the provided example is a mock response that simulates the following task:

{
  "Type": "Task",
  "Resource": "arn:aws:states:::aws-sdk:servicecatalog:describeRecord",
  "Parameters": {
    "Id": "rec-abcdefghijklm"
  },
  "ResultPath": "$",
  "Next": "Get Record Outputs",
  "Credentials": {
    "RoleArn": "arn:aws:iam::0123456789:role/role-with-servicecatalog-access"
  }
}
massfords commented 3 months ago

This looks like an issue with the expression parser. I'll have some time to look at this later today.

Thanks for the detailed report

burck1 commented 3 months ago

Well that was fast! I can confirm that the new v0.13.0 of asl-path-validator works as expected.

image

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 3.8.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: