Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ List<String> validateSuccessAction(String workflowId, String stepId, SuccessActi
}
}

if(successAction.getWorkflowId() != null && successAction.getType() != null && successAction.getType().equals("goto")) {
// when type `goto` workflowId must exist (if provided)
if(!workflowExists(workflowId)) {
errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)");
}
}

return errors;
}

Expand Down Expand Up @@ -493,6 +500,10 @@ boolean stepExists(String workflowId, String stepId) {
return this.stepIds.get(workflowId) != null && this.stepIds.get(workflowId).contains(stepId);
}

boolean workflowExists(String workflowId) {
return this.workflowIds.stream().anyMatch(p -> p.contains(workflowId));
}

List<String> validateWorkflowIdsUniqueness(List<Workflow> workflows) {
List<String> errors = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,44 @@ public void validateStepsWorkflowIdsWithoutRuntimeExpression() {
assertEquals(0, new OpenAPIWorkflowValidator().validateStepsWorkflowIds(steps, multipleWorkflowsSpecFiles).size());
}

@Test
void stepExists() {
OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator();
Map<String, Set<String>> stepIds = new HashMap<>();
stepIds.put("w1", Set.of("step-one", "step-two", "step-three"));

validator.stepIds = stepIds;

assertTrue(validator.stepExists("w1", "step-one"));
}

@Test
void stepNotFound() {
OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator();
Map<String, Set<String>> stepIds = new HashMap<>();
stepIds.put("w1", Set.of("step-one", "step-two", "step-three"));

validator.stepIds = stepIds;

assertFalse(validator.stepExists("w1", "step-dummy"));
}

@Test
void workflowExists() {
OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator();
validator.workflowIds.add("w1");

assertTrue(validator.workflowExists("w1"));
}

@Test
void workflowNotFound() {
OpenAPIWorkflowValidator validator = new OpenAPIWorkflowValidator();
validator.workflowIds.add("w1");

assertFalse(validator.workflowExists("dummy"));
}

@Test
void validWorkflowId() {
assertTrue(new OpenAPIWorkflowValidator().isValidWorkflowId("idOfTheWorkflow_1"));
Expand Down