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)
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 }
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ void parseFromFile() {
3030
3131 @ Test
3232 void parseFromUrl () {
33- final String WORKFLOWS_SPEC_FILE = "https://raw.githubusercontent.com/OAI/sig-workflows /main/examples /1.0.0/pet-coupons.workflow.yaml" ;
33+ final String WORKFLOWS_SPEC_FILE = "https://raw.githubusercontent.com/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 ());
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments