Skip to content

Commit

Permalink
Merge pull request #22 from API-Flows/verify-parameter-in
Browse files Browse the repository at this point in the history
Validation of parameter IN attribute
  • Loading branch information
gcatanese authored Feb 2, 2024
2 parents 77dbc4e + 5ac989a commit 16e2109
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/apiflows/model/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
}

public void addParameter(Parameter parameter) {
this.parameters.add(parameter);
}

@JsonProperty("successCriteria")
public List<Criterion> getSuccessCriteria() {
return successCriteria;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/apiflows/parser/OpenAPIWorkflowValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ List<String> validateStep(Step step, String workflowId ) {
if(step.getParameters() != null) {
for(Parameter parameter : step.getParameters()) {
errors.addAll(validateParameter(parameter, workflowId));

if(step.getWorkflowId() != null) {
// when the step in context specifies a workflowId the parameter IN must be defined
if(parameter.getIn() == null) {
errors.add("'Workflow[" + workflowId + "]' parameter IN must be defined");
}
}
}
}

Expand Down Expand Up @@ -209,13 +216,6 @@ List<String> validateParameter(Parameter parameter, String workflowId ) {
if(name == null) {
errors.add("'Workflow[" + workflowId + "]' parameter has no name");
}
if(parameter.getIn() == null) {
if(name != null) {
errors.add("Parameter '" + name + "' has no type");
} else {
errors.add("'Workflow[" + workflowId + "]' parameter has no type");
}
}
if(parameter.getIn() != null) {
if(!SUPPORTED_VALUES.contains(parameter.getIn())) {
if(name != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ void validateStepDependsOnSelf() {
assertEquals(1, validator.validateStep(step, WORKFLOW_ID).size());
}

@Test
void validateStepWithoutInAttribute() {
Step step = new Step()
.stepId("step-one")
.description("First step in the workflow")
.workflowId("workflow-id-2");
step.addParameter(new Parameter()
.name("param")
.value("value"));

String worklowId = "q1";

assertEquals(1, validator.validateStep(step, worklowId).size());
}


@Test
void validateParameter() {
Parameter parameter = new Parameter()
Expand Down

0 comments on commit 16e2109

Please sign in to comment.