Skip to content

Commit 77dbc4e

Browse files
authored
Merge pull request #21 from API-Flows/refactor-validation
Task - Refactor validator
2 parents f1ce303 + fcfeb38 commit 77dbc4e

File tree

12 files changed

+959
-120
lines changed

12 files changed

+959
-120
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,20 @@ public String getType() {
3131
public void setType(String type) {
3232
this.type = type;
3333
}
34+
35+
public Criterion condition(String condition) {
36+
this.condition = condition;
37+
return this;
38+
}
39+
40+
public Criterion context(String context) {
41+
this.context = context;
42+
return this;
43+
}
44+
45+
public Criterion type(String type) {
46+
this.type = type;
47+
return this;
48+
}
3449
}
3550

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package com.apiflows.model;
22

3+
import io.swagger.v3.oas.models.media.IntegerSchema;
4+
5+
import java.util.ArrayList;
36
import java.util.List;
47

58
public class FailureAction {
69

10+
private String type;
711
private String workflowId;
812
private String stepId;
913
private Long retryAfter;
1014
private Integer retryLimit;
1115
private List<Criterion> criteria;
1216

17+
public String getType() {
18+
return type;
19+
}
20+
21+
public void setType(String type) {
22+
this.type = type;
23+
}
24+
1325
public String getWorkflowId() {
1426
return workflowId;
1527
}
@@ -49,4 +61,36 @@ public List<Criterion> getCriteria() {
4961
public void setCriteria(List<Criterion> criteria) {
5062
this.criteria = criteria;
5163
}
64+
65+
public FailureAction type(String type) {
66+
this.type = type;
67+
return this;
68+
}
69+
70+
public FailureAction stepId(String stepId) {
71+
this.stepId = stepId;
72+
return this;
73+
}
74+
75+
public FailureAction workflowId(String workflowId) {
76+
this.workflowId = workflowId;
77+
return this;
78+
}
79+
80+
public FailureAction retryAfter(Long retryAfter) {
81+
this.retryAfter = retryAfter;
82+
return this;
83+
}
84+
85+
public FailureAction retryLimit(Integer retryLimit) {
86+
this.retryLimit = retryLimit;
87+
return this;
88+
}
89+
90+
public void addCriteria(Criterion criterion) {
91+
if(this.criteria == null) {
92+
this.criteria = new ArrayList<>();
93+
}
94+
this.criteria.add(criterion);
95+
}
5296
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ public String getDescription() {
3434
public void setDescription(String description) {
3535
this.description = description;
3636
}
37+
38+
public Info title(String title) {
39+
this.title = title;
40+
return this;
41+
}
42+
43+
public Info version(String version) {
44+
this.version = version;
45+
return this;
46+
}
47+
48+
public Info description(String description) {
49+
this.description = description;
50+
return this;
51+
}
52+
3753
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,35 @@ public void setStyle(String style) {
6262
public void set$ref(String $ref) {
6363
this.$ref = $ref;
6464
}
65+
66+
public Parameter name(String name) {
67+
this.name = name;
68+
return this;
69+
}
70+
71+
public Parameter in(String in) {
72+
this.in = in;
73+
return this;
74+
}
75+
76+
public Parameter value(String value) {
77+
this.value = value;
78+
return this;
79+
}
80+
81+
public Parameter target(String target) {
82+
this.target = target;
83+
return this;
84+
}
85+
86+
public Parameter style(String style) {
87+
this.style = style;
88+
return this;
89+
}
90+
91+
public Parameter $ref(String $ref) {
92+
this.$ref = $ref;
93+
return this;
94+
}
95+
6596
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ public boolean isOpenApi() {
4242
public boolean IsWorkflowsSpec() {
4343
return "workflowsSpec".equals(this.type);
4444
}
45+
46+
public SourceDescription name(String name) {
47+
this.name = name;
48+
return this;
49+
}
50+
51+
public SourceDescription url(String url) {
52+
this.url = url;
53+
return this;
54+
}
55+
56+
public SourceDescription type(String type) {
57+
this.type = type;
58+
return this;
59+
}
60+
4561
}

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,69 @@ public List<FailureAction> getOnFailure() {
132132
public void setOnFailure(List<FailureAction> onFailure) {
133133
this.onFailure = onFailure;
134134
}
135+
136+
public Step stepId(String stepId) {
137+
this.setStepId(stepId);
138+
return this;
139+
}
140+
141+
public Step operationId(String operationId) {
142+
this.setOperationId(operationId);
143+
return this;
144+
}
145+
146+
public Step operationRef(String operationRef) {
147+
this.setOperationRef(operationRef);
148+
return this;
149+
}
150+
151+
public Step operation(Operation operation) {
152+
this.setOperation(operation);
153+
return this;
154+
}
155+
156+
public Step workflowId(String workflowId) {
157+
this.setWorkflowId(workflowId);
158+
return this;
159+
}
160+
161+
public Step workflow(Workflow workflow) {
162+
this.setWorkflow(workflow);
163+
return this;
164+
}
165+
166+
public Step description(String description) {
167+
this.setDescription(description);
168+
return this;
169+
}
170+
171+
public Step dependsOn(String dependsOn) {
172+
this.setDependsOn(dependsOn);
173+
return this;
174+
}
175+
176+
public Step parameters(List<Parameter> parameters) {
177+
this.setParameters(parameters);
178+
return this;
179+
}
180+
181+
public Step successCriteria(List<Criterion> successCriteria) {
182+
this.setSuccessCriteria(successCriteria);
183+
return this;
184+
}
185+
186+
public Step outputs(Map<String, String> outputs) {
187+
this.setOutputs(outputs);
188+
return this;
189+
}
190+
191+
public Step onSuccess(List<SuccessAction> onSuccess) {
192+
this.setOnSuccess(onSuccess);
193+
return this;
194+
}
195+
196+
public Step onFailure(List<FailureAction> onFailure) {
197+
this.setOnFailure(onFailure);
198+
return this;
199+
}
135200
}

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

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

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
public class SuccessAction {
@@ -40,4 +41,26 @@ public List<Criterion> getCriteria() {
4041
public void setCriteria(List<Criterion> criteria) {
4142
this.criteria = criteria;
4243
}
44+
45+
public void addCriteria(Criterion criterion) {
46+
if(this.criteria == null) {
47+
this.criteria = new ArrayList<>();
48+
}
49+
this.criteria.add(criterion);
50+
}
51+
52+
public SuccessAction type(String type) {
53+
this.type = type;
54+
return this;
55+
}
56+
57+
public SuccessAction workflowId(String workflowId) {
58+
this.workflowId = workflowId;
59+
return this;
60+
}
61+
62+
public SuccessAction stepId(String stepId) {
63+
this.stepId = stepId;
64+
return this;
65+
}
4366
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void setSteps(List<Step> steps) {
6262
this.steps = steps;
6363
}
6464

65+
public Workflow addStep(Step step) {
66+
this.steps.add(step);
67+
return this;
68+
}
69+
6570
@JsonProperty("outputs")
6671
public Map<String, String> getOutputs() {
6772
return outputs;
@@ -70,4 +75,24 @@ public Map<String, String> getOutputs() {
7075
public void setOutputs(Map<String, String> outputs) {
7176
this.outputs = outputs;
7277
}
78+
79+
public Workflow workflowId(String workflowId) {
80+
this.workflowId = workflowId;
81+
return this;
82+
}
83+
84+
public Workflow summary(String summary) {
85+
this.summary = summary;
86+
return this;
87+
}
88+
public Workflow description(String description) {
89+
this.description = description;
90+
return this;
91+
}
92+
93+
public Workflow inputs(Schema inputs) {
94+
this.inputs = inputs;
95+
return this;
96+
}
97+
7398
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public OpenAPIWorkflowParserResult parse(String input, ParseOptions options) {
6767
result.setOpenAPIWorkflow(openAPIWorkflow);
6868

6969
if(options != null && options.isApplyValidation()) {
70-
OpenAPIWorkflowValidatorResult validatorResult = new OpenAPIWorkflowValidator().validate(openAPIWorkflow);
70+
OpenAPIWorkflowValidatorResult validatorResult = new OpenAPIWorkflowValidator(openAPIWorkflow).validate();
7171
result.setValid(validatorResult.isValid());
7272
result.setErrors(validatorResult.getErrors());
7373
}

0 commit comments

Comments
 (0)