sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

Validation fails when transition.NextState is equal to currentState

Open Kshitiz1403 opened this issue 9 months ago • 5 comments

What happened: When doing state transitions, whenever the transition.NextState is defined as the currentState, the validation fails with the error Error:Field validation for 'NextState' failed on the 'recursivestate' tag"

What you expected to happen: The validation should not fail when transitioning to the same state.

How to reproduce it: Take for example this state

{
  "name": "FineUser",
  "type": "operation",
  "actions": [
    {
      "functionRef": {
        "refName": "FineUserFn"
      }
    }
  ],
  "transition": "CallExternalAPI",
  "onErrors": [
    {
      "errorRef": "ServicesNotAvailable",
      "transition": "FineUser"
    },
    {
      "errorRef": "DefaultErrorRef",
      "transition": "Reject"
    }
  ]
}

The validation here fails for onErrors[0] since it is looking to transition to the state FineUser which seems to be not handled in the SDK.

One more example of this is -

{
  "name": "UserActionSignal",
  "type": "switch",
  "eventConditions": [
    {
      "eventRef": "fine_user",
      "transition": "FineUser"
    },
    {
      "eventRef": "reward_user",
      "transition": "RewardUser"
    }
  ],
  "metadata": {
    "moduleNameTag": "USER_REWARD_INPUT",
    "moduleStatusTag": "WAIT"
  },
  "timeouts": {
    "eventTimeout": "PT5S"
  },
  "defaultCondition": {
    "transition": "UserActionSignal"
  }
}

here, the default transition is configured as UserActionSignal but since the nextState is same as the currentState, the validator throws the error.

Anything else we need to know?:

Environment:

  • SDK version: v2.2.5
  • Go version: go1.20.14 darwin/arm64

Kshitiz1403 avatar May 27 '24 11:05 Kshitiz1403