Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/com/apiflows/model/FailureAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.apiflows.model;

import io.swagger.v3.oas.models.media.IntegerSchema;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -10,7 +8,7 @@ public class FailureAction {
private String type;
private String workflowId;
private String stepId;
private Long retryAfter;
private Double retryAfter;
private Integer retryLimit;
private List<Criterion> criteria;

Expand Down Expand Up @@ -38,11 +36,11 @@ public void setStepId(String stepId) {
this.stepId = stepId;
}

public Long getRetryAfter() {
public Double getRetryAfter() {
return retryAfter;
}

public void setRetryAfter(Long retryAfter) {
public void setRetryAfter(Double retryAfter) {
this.retryAfter = retryAfter;
}

Expand Down Expand Up @@ -77,7 +75,7 @@ public FailureAction workflowId(String workflowId) {
return this;
}

public FailureAction retryAfter(Long retryAfter) {
public FailureAction retryAfter(Double retryAfter) {
this.retryAfter = retryAfter;
return this;
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/apiflows/model/PayloadReplacement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.apiflows.model;

public class PayloadReplacement {

private String target;
private String value;

public String getTarget() {
return target;
}

public void setTarget(String target) {
this.target = target;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/apiflows/model/RequestBody.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.apiflows.model;

import java.util.List;

public class RequestBody {

private String contentType;
private Object payload;
private PayoadReplacement payoadReplacement;
private List<PayloadReplacement> replacements;

public String getContentType() {
return contentType;
Expand All @@ -22,11 +24,11 @@ public void setPayload(Object payload) {
this.payload = payload;
}

public PayoadReplacement getPayoadReplacement() {
return payoadReplacement;
public List<PayloadReplacement> getReplacements() {
return replacements;
}

public void setPayoadReplacement(PayoadReplacement payoadReplacement) {
this.payoadReplacement = payoadReplacement;
public void setReplacements(List<PayloadReplacement> replacements) {
this.replacements = replacements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.apiflows.model.OpenAPIWorkflow;

import java.util.ArrayList;
import java.util.List;

public class OpenAPIWorkflowParserResult {
Expand All @@ -10,7 +11,7 @@ public enum Format {
JSON, YAML
}
private boolean valid = true;
private List<String> errors = null;
private List<String> errors = new ArrayList<>();
private OpenAPIWorkflow openAPIWorkflow;

private String location;
Expand Down
51 changes: 25 additions & 26 deletions src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
}

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

String source;

Expand Down Expand Up @@ -299,25 +299,17 @@
}
}

if(successAction.getWorkflowId() == null && successAction.getStepId() == null) {
errors.add("Step " + stepId + " SuccessAction must define either workflowId or stepId");
}

if(successAction.getWorkflowId() != null && successAction.getStepId() != null) {
errors.add("Step " + stepId + " SuccessAction cannot define both workflowId and stepId");
}

if(successAction.getStepId() != null && successAction.getType() != null && successAction.getType().equals("goto")) {
// when type `goto` stepId must exist (if provided)
if (!stepExists(workflowId, successAction.getStepId())) {
errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)");
if("goto".equals(successAction.getType())) {
errors.addAll(validateGotoTarget(stepId, "SuccessAction", successAction.getStepId(), successAction.getWorkflowId()));
if(successAction.getStepId() != null) {
if (!stepExists(workflowId, successAction.getStepId())) {
errors.add("Step " + stepId + " SuccessAction stepId is invalid (no such a step exists)");
}
}
}

if(successAction.getWorkflowId() != null && successAction.getType() != null && successAction.getType().equals("goto")) {
// when type `goto` workflowId must exist (if provided)
if(!workflowExists(workflowId)) {
errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)");
if(successAction.getWorkflowId() != null) {
if(!workflowExists(successAction.getWorkflowId())) {

Check warning on line 310 in src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=API-Flows_openapi-workflow-parser&issues=AZ05TyR31XV5X7ZcJjo5&open=AZ05TyR31XV5X7ZcJjo5&pullRequest=76
errors.add("Step " + stepId + " SuccessAction workflowId is invalid (no such a workflow exists)");
}
}
}

Expand All @@ -339,12 +331,8 @@
}
}

if(failureAction.getWorkflowId() == null && failureAction.getStepId() == null) {
errors.add("Step " + stepId + " FailureAction must define either workflowId or stepId");
}

if(failureAction.getWorkflowId() != null && failureAction.getStepId() != null) {
errors.add("Step " + stepId + " FailureAction cannot define both workflowId and stepId");
if("goto".equals(failureAction.getType())) {
errors.addAll(validateGotoTarget(stepId, "FailureAction", failureAction.getStepId(), failureAction.getWorkflowId()));
}

if(failureAction.getRetryAfter() != null && failureAction.getRetryAfter() < 0) {
Expand Down Expand Up @@ -434,7 +422,7 @@
}

String getWorkflowIdRegularExpression() {
return "[A-Za-z0-9_\\\\-]++";
return "[A-Za-z0-9_\\-]+";
}
String getComponentKeyRegularExpression() {
return "^[a-zA-Z0-9\\.\\-_]+$";
Expand Down Expand Up @@ -595,4 +583,15 @@
return name != null && name.startsWith("$");
}

private List<String> validateGotoTarget(String stepId, String actionLabel, String targetStepId, String targetWorkflowId) {
List<String> errors = new ArrayList<>();
if (targetWorkflowId == null && targetStepId == null) {
errors.add("Step " + stepId + " " + actionLabel + " must define either workflowId or stepId");
}
if (targetWorkflowId != null && targetStepId != null) {
errors.add("Step " + stepId + " " + actionLabel + " cannot define both workflowId and stepId");
}
return errors;
}

}
Loading
Loading