Incorrect order of workflow steps when explicitly setting `stepNo`
I'm not 100% clear how the workflow steps endpoints are supposed to work.
I'll start with: how to re-order steps?
Here's what I did:
- Create new workflow
curl "http://localhost:8080/api/workflows" \
-X POST \
-H "Authorization: Bearer ..." \
-H "Content-Type: application/json" \
-d '{"label":"New workflow","description":"New workflow"}'
- Create new step for the above workflow
curl "http://localhost:8080/api/workflows/:workflowId/steps" \
-X POST \
-H "Authorization: Bearer ..." \
-H "Content-Type: application/json" \
-d '{"label":"First step","description":"First step"}'
- Create more steps for the above workflow, this time with explicitly specifying
stepNo
curl "http://localhost:8080/api/workflows/:workflowId/steps" \
-X POST \
-H "Authorization: Bearer ..." \
-H "Content-Type: application/json" \
-d '{"label":"Second step","description":"Second step","stepNo":2}'
curl "http://localhost:8080/api/workflows/:workflowId/steps" \
-X POST \
-H "Authorization: Bearer ..." \
-H "Content-Type: application/json" \
-d '{"label":"Another step","description":"Another step","stepNo":1}'
** Steps must not be a sparse array, so stepNo
must not be larger than steps.length + 1. When the position is already occupied (i.e. stepNo: 1
in this example), items will be shifted up one step to make space.** correct?
- Check workflow order:
curl "http://localhost:8080/api/workflows/:workflowId" | jq '.composedOf[].label'
The steps are now ordered as expected: ["Another step","First step","Second step"]
- Now the question: I want to move "Another step" to the end, and rename it to "Third step". So I tried to PUT it to
stepNo: 3
and expected the other two steps to be pushed down one step to make space:
curl "http://localhost:8080/api/workflows/:workflowId/steps/:stepIdOfAnotherStep" \
-X PUT \
-H "Authorization: Bearer ..." \
-H "Content-Type: application/json" \
-d '{"label":"Third step","description":"Third step","stepNo":3}'
- Check workflow order:
curl "http://localhost:8080/api/workflows/:workflowId" | jq '.composedOf[].label'
The order now is ["First step","Third step","Second step"]
but i had expected ["First step","Second step","Third step"]
. What am I missing?