Guard against null parameter fields in OpenAPI operation parsing#1453
Guard against null parameter fields in OpenAPI operation parsing#1453mcruzdev wants to merge 5 commits into
Conversation
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens OpenAPI/Swagger operation parameter handling by normalizing default values and adding null-safety around parameter fields during parameter extraction.
Changes:
- Default
UnifiedOpenAPI.Parameter.requiredtofalsewhen unspecified. - Add null checks for
parameter.in()andschemawhen filtering/processing Swagger v2 body parameters.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| impl/openapi/src/main/java/io/serverlessworkflow/impl/executors/openapi/UnifiedOpenAPI.java | Normalizes Parameter.required to a non-null default (false). |
| impl/openapi/src/main/java/io/serverlessworkflow/impl/executors/openapi/OperationDefinition.java | Adds null-safety when checking parameter location (in) and resolving schema refs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
| if (operation.hasParameters()) { | ||
| for (UnifiedOpenAPI.Parameter parameter : operation.parameters()) { | ||
| if (parameter.in().equals("body")) { | ||
| if (parameter.in() != null && "body".equals(parameter.in())) { |
There was a problem hiding this comment.
| if (parameter.in() != null && "body".equals(parameter.in())) { | |
| if ("body".equals(parameter.in())) { |
| && operation.parameters() != null) { | ||
| operation.parameters().stream() | ||
| .filter(p -> p.in().equals("body")) | ||
| .filter(p -> p.in() != null && "body".equals(p.in())) |
There was a problem hiding this comment.
| .filter(p -> p.in() != null && "body".equals(p.in())) | |
| .filter(p -> "body".equals(p.in())) |
| } | ||
|
|
||
| public record Parameter(String name, String in, Boolean required, Schema schema) {} | ||
| public record Parameter(String name, String in, Boolean required, Schema schema) { |
There was a problem hiding this comment.
Im wondering if we can make required field a boolean rather than a Boolean and skip that check
| public record Parameter(String name, String in, Boolean required, Schema schema) { | ||
| public Parameter { | ||
| required = required != null ? required : Boolean.FALSE; | ||
| } | ||
| } |
There was a problem hiding this comment.
Yes, I tested it and it is working
| public record Parameter(String name, String in, Boolean required, Schema schema) { | |
| public Parameter { | |
| required = required != null ? required : Boolean.FALSE; | |
| } | |
| } | |
| public record Parameter(String name, String in, boolean required, Schema schema) { | |
| } |
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
| } | ||
|
|
||
| public record Parameter(String name, String in, Boolean required, Schema schema) {} | ||
| public record Parameter(String name, String in, boolean required, Schema schema) {} |
| UnifiedOpenAPI.Schema schema = p.schema(); | ||
| if (schema.hasRef()) { | ||
| if (schema != null && schema.hasRef()) { | ||
| String ref = schema.ref(); | ||
| schema = openAPI.resolveSchema(ref); | ||
| } |
| if (openAPI.swaggerVersion() == UnifiedOpenAPI.SwaggerVersion.SWAGGER_V2 | ||
| && operation.parameters() != null) { | ||
| operation.parameters().stream() |
Guard against null parameter fields in OpenAPI operation parsing
Add null checks before dereferencing Parameter.in() and Schema in
OperationDefinition, so parameters without an explicit "in" value or
schema no longer trigger NullPointerExceptions during parsing.