Skip to content

Commit f1ce303

Browse files
authored
Merge pull request #20 from API-Flows/workflowid-validation
WorkflowId validation
2 parents eaf7246 + 62ffaeb commit f1ce303

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
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/OpenAPIWorkflowParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void parseFromFile() {
3030

3131
@Test
3232
void parseFromUrl() {
33-
final String WORKFLOWS_SPEC_FILE = "https://github.com/raw/OAI/sig-workflows/main/examples/1.0.0/pet-coupons.workflow.yaml";
33+
final String WORKFLOWS_SPEC_FILE = "https://github.com/raw/API-Flows/openapi-workflow-parser/main/src/test/resources/1.0.0/pet-coupons.workflow.yaml";
3434

3535
OpenAPIWorkflowParserResult result = parser.parse(WORKFLOWS_SPEC_FILE);
3636
assertNotNull(result.getOpenAPIWorkflow());

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)