Skip to content

Commit dd0089f

Browse files
authored
Guard against null parameter fields in OpenAPI operation parsing (#1453)
* Guard against null parameter fields in OpenAPI operation parsing Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Guard operation.parameters from NPE Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Apply pull request suggestions Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Compare enum with == operator Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Apply @fjtirado suggestions Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * Use hasParameters instead != null check Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> --------- Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 5fc29d6 commit dd0089f

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

impl/openapi/src/main/java/io/serverlessworkflow/impl/executors/openapi/OperationDefinition.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ List<ParameterDefinition> getParameters() {
6060
List<ParameterDefinition> paramDefinitions = new ArrayList<>();
6161
if (operation.hasParameters()) {
6262
for (UnifiedOpenAPI.Parameter parameter : operation.parameters()) {
63-
if (parameter.in().equals("body")) {
63+
if ("body".equals(parameter.in())) {
6464
continue; // body parameters are handled separately
6565
}
6666

@@ -70,13 +70,14 @@ List<ParameterDefinition> getParameters() {
7070
}
7171
}
7272

73-
if (openAPI.swaggerVersion().equals(UnifiedOpenAPI.SwaggerVersion.SWAGGER_V2)) {
73+
if (openAPI.swaggerVersion() == UnifiedOpenAPI.SwaggerVersion.SWAGGER_V2
74+
&& operation.hasParameters()) {
7475
operation.parameters().stream()
75-
.filter(p -> p.in().equals("body"))
76+
.filter(p -> "body".equals(p.in()))
7677
.forEach(
7778
p -> {
7879
UnifiedOpenAPI.Schema schema = p.schema();
79-
if (schema.hasRef()) {
80+
if (schema != null && schema.hasRef()) {
8081
String ref = schema.ref();
8182
schema = openAPI.resolveSchema(ref);
8283
}

impl/openapi/src/main/java/io/serverlessworkflow/impl/executors/openapi/UnifiedOpenAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public boolean hasRequestBody() {
165165
}
166166
}
167167

168-
public record Parameter(String name, String in, Boolean required, Schema schema) {}
168+
public record Parameter(String name, String in, boolean required, Schema schema) {}
169169

170170
public record RequestBody(Content content) {}
171171

0 commit comments

Comments
 (0)