File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
main/java/com/apiflows/parser
test/java/com/apiflows/parser Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,11 @@ public OpenAPIWorkflowValidatorResult validate(OpenAPIWorkflow openAPIWorkflow)
64
64
if (workflow .getWorkflowId () == null || workflow .getWorkflowId ().isEmpty ()) {
65
65
result .addError ("'Workflow[" + i + "] workflowId' is undefined" );
66
66
}
67
+
68
+ if (!isValidWorkflowId (workflow .getWorkflowId ())) {
69
+ result .addError ("'Workflow[" + i + "] workflowId' format is invalid (should match regex " + getWorkflowIdRegularExpression () + ")" );
70
+ }
71
+
67
72
if (workflow .getSteps () == null ) {
68
73
result .addError ("'Workflow " + workflow .getWorkflowId () + "' no Steps are undefined" );
69
74
}
@@ -162,6 +167,10 @@ public OpenAPIWorkflowValidatorResult validate(OpenAPIWorkflow openAPIWorkflow)
162
167
return result ;
163
168
}
164
169
170
+ boolean isValidWorkflowId (String workflowId ) {
171
+ return Pattern .matches (getWorkflowIdRegularExpression (), workflowId );
172
+ }
173
+
165
174
boolean isValidStepId (String stepId ) {
166
175
return Pattern .matches (getStepIdRegularExpression (), stepId );
167
176
}
@@ -170,6 +179,9 @@ String getStepIdRegularExpression() {
170
179
return "[A-Za-z0-9_\\ -]+" ;
171
180
}
172
181
182
+ String getWorkflowIdRegularExpression () {
183
+ return "[A-Za-z0-9_\\ \\ -]++" ;
184
+ }
173
185
boolean isValidOutputsKey (String key ) {
174
186
return Pattern .matches (getOutputsKeyRegularExpression (), key );
175
187
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ void parseFromFile() {
30
30
31
31
@ Test
32
32
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" ;
34
34
35
35
OpenAPIWorkflowParserResult result = parser .parse (WORKFLOWS_SPEC_FILE );
36
36
assertNotNull (result .getOpenAPIWorkflow ());
Original file line number Diff line number Diff line change @@ -16,4 +16,14 @@ void validate() {
16
16
assertFalse (result .getErrors ().isEmpty ());
17
17
assertEquals ("'workflowsSpec' is undefined" , result .getErrors ().get (0 ));
18
18
}
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
+ }
19
29
}
You can’t perform that action at this time.
0 commit comments