Skip to content

Commit b4be1fe

Browse files
authored
Merge pull request #76 from API-Flows/fix/arazzo-spec-inconsistencies
Fix Arazzo spec inconsistencies in validator and model
2 parents 1e15da0 + a3e5e1e commit b4be1fe

6 files changed

Lines changed: 172 additions & 124 deletions

File tree

src/main/java/com/apiflows/model/FailureAction.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.apiflows.model;
22

3-
import io.swagger.v3.oas.models.media.IntegerSchema;
4-
53
import java.util.ArrayList;
64
import java.util.List;
75

@@ -10,7 +8,7 @@ public class FailureAction {
108
private String type;
119
private String workflowId;
1210
private String stepId;
13-
private Long retryAfter;
11+
private Double retryAfter;
1412
private Integer retryLimit;
1513
private List<Criterion> criteria;
1614

@@ -38,11 +36,11 @@ public void setStepId(String stepId) {
3836
this.stepId = stepId;
3937
}
4038

41-
public Long getRetryAfter() {
39+
public Double getRetryAfter() {
4240
return retryAfter;
4341
}
4442

45-
public void setRetryAfter(Long retryAfter) {
43+
public void setRetryAfter(Double retryAfter) {
4644
this.retryAfter = retryAfter;
4745
}
4846

@@ -77,7 +75,7 @@ public FailureAction workflowId(String workflowId) {
7775
return this;
7876
}
7977

80-
public FailureAction retryAfter(Long retryAfter) {
78+
public FailureAction retryAfter(Double retryAfter) {
8179
this.retryAfter = retryAfter;
8280
return this;
8381
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.apiflows.model;
2+
3+
public class PayloadReplacement {
4+
5+
private String target;
6+
private String value;
7+
8+
public String getTarget() {
9+
return target;
10+
}
11+
12+
public void setTarget(String target) {
13+
this.target = target;
14+
}
15+
16+
public String getValue() {
17+
return value;
18+
}
19+
20+
public void setValue(String value) {
21+
this.value = value;
22+
}
23+
}

src/main/java/com/apiflows/model/RequestBody.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.apiflows.model;
22

3+
import java.util.List;
4+
35
public class RequestBody {
46

57
private String contentType;
68
private Object payload;
7-
private PayoadReplacement payoadReplacement;
9+
private List<PayloadReplacement> replacements;
810

911
public String getContentType() {
1012
return contentType;
@@ -22,11 +24,11 @@ public void setPayload(Object payload) {
2224
this.payload = payload;
2325
}
2426

25-
public PayoadReplacement getPayoadReplacement() {
26-
return payoadReplacement;
27+
public List<PayloadReplacement> getReplacements() {
28+
return replacements;
2729
}
2830

29-
public void setPayoadReplacement(PayoadReplacement payoadReplacement) {
30-
this.payoadReplacement = payoadReplacement;
31+
public void setReplacements(List<PayloadReplacement> replacements) {
32+
this.replacements = replacements;
3133
}
3234
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.apiflows.model.OpenAPIWorkflow;
44

5+
import java.util.ArrayList;
56
import java.util.List;
67

78
public class OpenAPIWorkflowParserResult {
@@ -10,7 +11,7 @@ public enum Format {
1011
JSON, YAML
1112
}
1213
private boolean valid = true;
13-
private List<String> errors = null;
14+
private List<String> errors = new ArrayList<>();
1415
private OpenAPIWorkflow openAPIWorkflow;
1516

1617
private String location;

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ List<String> validateStep(Step step, String workflowId ) {
217217
}
218218

219219
List<String> validateParameter(Parameter parameter, String workflowId, String componentName) {
220-
List<String> SUPPORTED_VALUES = Arrays.asList("path", "query", "header", "cookie", "body");
220+
List<String> SUPPORTED_VALUES = Arrays.asList("path", "query", "header", "cookie");
221221

222222
String source;
223223

@@ -299,25 +299,17 @@ List<String> validateSuccessAction(String workflowId, String stepId, SuccessActi
299299
}
300300
}
301301

302-
if(successAction.getWorkflowId() == null && successAction.getStepId() == null) {
303-
errors.add("Step " + stepId + " SuccessAction must define either workflowId or stepId");
304-
}
305-
306-
if(successAction.getWorkflowId() != null && successAction.getStepId() != null) {
307-
errors.add("Step " + stepId + " SuccessAction cannot define both workflowId and stepId");
308-
}
309-
310-
if(successAction.getStepId() != null && successAction.getType() != null && successAction.getType().equals("goto")) {
311-
// when type `goto` stepId must exist (if provided)
312-
if (!stepExists(workflowId, successAction.getStepId())) {
313-
errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)");
302+
if("goto".equals(successAction.getType())) {
303+
errors.addAll(validateGotoTarget(stepId, "SuccessAction", successAction.getStepId(), successAction.getWorkflowId()));
304+
if(successAction.getStepId() != null) {
305+
if (!stepExists(workflowId, successAction.getStepId())) {
306+
errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)");
307+
}
314308
}
315-
}
316-
317-
if(successAction.getWorkflowId() != null && successAction.getType() != null && successAction.getType().equals("goto")) {
318-
// when type `goto` workflowId must exist (if provided)
319-
if(!workflowExists(workflowId)) {
320-
errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)");
309+
if(successAction.getWorkflowId() != null) {
310+
if(!workflowExists(successAction.getWorkflowId())) {
311+
errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)");
312+
}
321313
}
322314
}
323315

@@ -339,12 +331,8 @@ List<String> validateFailureAction(String workflowId, String stepId, FailureActi
339331
}
340332
}
341333

342-
if(failureAction.getWorkflowId() == null && failureAction.getStepId() == null) {
343-
errors.add("Step " + stepId + " FailureAction must define either workflowId or stepId");
344-
}
345-
346-
if(failureAction.getWorkflowId() != null && failureAction.getStepId() != null) {
347-
errors.add("Step " + stepId + " FailureAction cannot define both workflowId and stepId");
334+
if("goto".equals(failureAction.getType())) {
335+
errors.addAll(validateGotoTarget(stepId, "FailureAction", failureAction.getStepId(), failureAction.getWorkflowId()));
348336
}
349337

350338
if(failureAction.getRetryAfter() != null && failureAction.getRetryAfter() < 0) {
@@ -434,7 +422,7 @@ String getStepIdRegularExpression() {
434422
}
435423

436424
String getWorkflowIdRegularExpression() {
437-
return "[A-Za-z0-9_\\\\-]++";
425+
return "[A-Za-z0-9_\\-]+";
438426
}
439427
String getComponentKeyRegularExpression() {
440428
return "^[a-zA-Z0-9\\.\\-_]+$";
@@ -595,4 +583,15 @@ boolean isRuntimeExpression(String name) {
595583
return name != null && name.startsWith("$");
596584
}
597585

586+
private List<String> validateGotoTarget(String stepId, String actionLabel, String targetStepId, String targetWorkflowId) {
587+
List<String> errors = new ArrayList<>();
588+
if (targetWorkflowId == null && targetStepId == null) {
589+
errors.add("Step " + stepId + " " + actionLabel + " must define either workflowId or stepId");
590+
}
591+
if (targetWorkflowId != null && targetStepId != null) {
592+
errors.add("Step " + stepId + " " + actionLabel + " cannot define both workflowId and stepId");
593+
}
594+
return errors;
595+
}
596+
598597
}

0 commit comments

Comments
 (0)