Skip to content

Validation of parameter IN attribute #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2024
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
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