Skip to content

Commit 81ee306

Browse files
committed
Validation of workflowId
1 parent eaf7246 commit 81ee306

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public OpenAPIWorkflowValidatorResult validate(OpenAPIWorkflow openAPIWorkflow)
6464
if (workflow.getWorkflowId() == null || workflow.getWorkflowId().isEmpty()) {
6565
result.addError("'Workflow[" + i + "] workflowId' is undefined");
6666
}
67+
68+
if (!isValidWorkflowId(workflow.getWorkflowId())) {
69+
result.addError("'Workflow[" + i + "] workflowId' format is invalid (should match regex " + getWorkflowIdRegularExpression() + ")");
70+
}
71+
6772
if (workflow.getSteps() == null) {
6873
result.addError("'Workflow " + workflow.getWorkflowId() + "' no Steps are undefined");
6974
}
@@ -162,6 +167,10 @@ public OpenAPIWorkflowValidatorResult validate(OpenAPIWorkflow openAPIWorkflow)
162167
return result;
163168
}
164169

170+
boolean isValidWorkflowId(String workflowId) {
171+
return Pattern.matches(getWorkflowIdRegularExpression(), workflowId);
172+
}
173+
165174
boolean isValidStepId(String stepId) {
166175
return Pattern.matches(getStepIdRegularExpression(), stepId);
167176
}
@@ -170,6 +179,9 @@ String getStepIdRegularExpression() {
170179
return "[A-Za-z0-9_\\-]+";
171180
}
172181

182+
String getWorkflowIdRegularExpression() {
183+
return "[A-Za-z0-9_\\\\-]++";
184+
}
173185
boolean isValidOutputsKey(String key) {
174186
return Pattern.matches(getOutputsKeyRegularExpression(), key);
175187
}

src/test/java/com/apiflows/parser/OpenAPIWorkflowValidatorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ void validate() {
1616
assertFalse(result.getErrors().isEmpty());
1717
assertEquals("'workflowsSpec' is undefined", result.getErrors().get(0));
1818
}
19+
20+
@Test
21+
void validWorkflowId() {
22+
assertTrue(new OpenAPIWorkflowValidator().isValidWorkflowId("idOfTheWorkflow_1"));
23+
}
24+
25+
@Test
26+
void invalidWorkflowId() {
27+
assertFalse(new OpenAPIWorkflowValidator().isValidWorkflowId("workflow id"));
28+
}
1929
}

0 commit comments

Comments
 (0)