(aws-stepfunctions): CustomState generates wrong code when using `Type: Choice`
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I am using the `CustomState` construct to generate a `Choice` with `JSONata`. The problem is that since `CustomState` implements `INextable`, this adds an `End` property which is invalid for the `Choice` state.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
For this CDK construct
```
const shouldContinue = new sfn.CustomState(this, 'ShouldContinue', {
stateJson: {
Type: 'Choice',
QueryLanguage: 'JSONata',
Default: 'AnalysisComplete',
Choices: [
{
Next: 'ProcessDiscoveredUrls',
Condition:
'{% $count($states.input.nextBatch) > 0 and $count($states.input.visitedUrls) <= $states.input.maxPages %}',
},
],
},
});
```
I would expect, the proper JSON to be constructed without the `End` property.
### Current Behavior
This is the generated JSON
```
{
"End": true,
"Type": "Choice",
"QueryLanguage": "JSONata",
"Default": "AnalysisComplete",
"Choices":[{
"Next": "ProcessDiscoveredUrls",
"Condition": "{% $count($states.input.nextBatch) > 0 and $count($states.input.visitedUrls) <= $states.input.maxPages %}"
}]
}
```
### Reproduction Steps
This is easily reproduced using the construct above.
### Possible Solution
One solution would be adding an if statement to conditionally call `renderNextEnd()` in `toStateJson()` but then `CustomState` wouldn't really implement `INextable`. There needs to be a construct one level higher that doesn't implement `INextable`.
### Additional Information/Context
_No response_
### CDK CLI Version
2.173.2 (build f8e6207)
### Framework Version
_No response_
### Node.js Version
20
### OS
AL2
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start at the CustomState implementation, especially toStateJson() and renderNextEnd(), which the issue identifies as the relevant entry points. Reproduce the supplied Choice/JSONata example and inspect the generated state JSON; done means the Choice output no longer contains the invalid End property while valid nextable states retain their expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100