Fix multipart fields in vertx - #24668
Conversation
There was a problem hiding this comment.
3 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/JavaVertXWebServer/formParams.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/JavaVertXWebServer/formParams.mustache:11">
P3: Optional file parameters generate an empty `if` block; wrap the entire null check in `{{#required}}` so optional uploads emit no dead branch.</violation>
<violation number="2" location="modules/openapi-generator/src/main/resources/JavaVertXWebServer/formParams.mustache:11">
P2: This template change breaks the existing unit test for this generator. `JavaVertXWebServerCodegenTest.itShouldCheckFileUploadEmptiness` still asserts the old output strings `if (routingContext.fileUploads().isEmpty()) {`, `} else {`, and `_file = routingContext.fileUploads().iterator().next();`, but the template no longer emits any of them, so the test will fail and the module build/CI will go red. Please update the test assertions (and ideally add coverage for the new field-name filter plus the 400-on-missing-required-file behavior) alongside this template change.</violation>
</file>
<file name="samples/server/petstore/java-vertx-web/src/main/java/org/openapitools/vertxweb/server/api/PetApiHandler.java">
<violation number="1" location="samples/server/petstore/java-vertx-web/src/main/java/org/openapitools/vertxweb/server/api/PetApiHandler.java:219">
P3: The `if (_file == null) { }` block is empty dead code: when the multipart `file` field is optional (as in the petstore spec), the generated handler does nothing on a missing file and proceeds to call `api.uploadFile(petId, null)`. Wrap the null-check in the template's `{{#required}}` section so it is only emitted with the `fail(400); return;` body, avoiding a misleading no-op for optional uploads.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| .filter(upload -> "{{baseName}}".equals(upload.name())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| if ({{paramName}} == null) { |
There was a problem hiding this comment.
P2: This template change breaks the existing unit test for this generator. JavaVertXWebServerCodegenTest.itShouldCheckFileUploadEmptiness still asserts the old output strings if (routingContext.fileUploads().isEmpty()) {, } else {, and _file = routingContext.fileUploads().iterator().next();, but the template no longer emits any of them, so the test will fail and the module build/CI will go red. Please update the test assertions (and ideally add coverage for the new field-name filter plus the 400-on-missing-required-file behavior) alongside this template change.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaVertXWebServer/formParams.mustache, line 11:
<comment>This template change breaks the existing unit test for this generator. `JavaVertXWebServerCodegenTest.itShouldCheckFileUploadEmptiness` still asserts the old output strings `if (routingContext.fileUploads().isEmpty()) {`, `} else {`, and `_file = routingContext.fileUploads().iterator().next();`, but the template no longer emits any of them, so the test will fail and the module build/CI will go red. Please update the test assertions (and ideally add coverage for the new field-name filter plus the 400-on-missing-required-file behavior) alongside this template change.</comment>
<file context>
@@ -4,14 +4,15 @@
+ .filter(upload -> "{{baseName}}".equals(upload.name()))
+ .findFirst()
+ .orElse(null);
+ if ({{paramName}} == null) {
{{#required}}
routingContext.fail(400);
</file context>
| if ({{paramName}} == null) { | ||
| {{#required}} | ||
| routingContext.fail(400); | ||
| return; | ||
| {{/required}} | ||
| } else { | ||
| {{paramName}} = routingContext.fileUploads().iterator().next(); | ||
| } |
There was a problem hiding this comment.
P3: Optional file parameters generate an empty if block; wrap the entire null check in {{#required}} so optional uploads emit no dead branch.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaVertXWebServer/formParams.mustache, line 11:
<comment>Optional file parameters generate an empty `if` block; wrap the entire null check in `{{#required}}` so optional uploads emit no dead branch.</comment>
<file context>
@@ -4,14 +4,15 @@
+ .filter(upload -> "{{baseName}}".equals(upload.name()))
+ .findFirst()
+ .orElse(null);
+ if ({{paramName}} == null) {
{{#required}}
routingContext.fail(400);
</file context>
| if ({{paramName}} == null) { | |
| {{#required}} | |
| routingContext.fail(400); | |
| return; | |
| {{/required}} | |
| } else { | |
| {{paramName}} = routingContext.fileUploads().iterator().next(); | |
| } | |
| {{#required}} | |
| if ({{paramName}} == null) { | |
| routingContext.fail(400); | |
| return; | |
| } | |
| {{/required}} |
| .filter(upload -> "file".equals(upload.name())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| if (_file == null) { |
There was a problem hiding this comment.
P3: The if (_file == null) { } block is empty dead code: when the multipart file field is optional (as in the petstore spec), the generated handler does nothing on a missing file and proceeds to call api.uploadFile(petId, null). Wrap the null-check in the template's {{#required}} section so it is only emitted with the fail(400); return; body, avoiding a misleading no-op for optional uploads.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/java-vertx-web/src/main/java/org/openapitools/vertxweb/server/api/PetApiHandler.java, line 219:
<comment>The `if (_file == null) { }` block is empty dead code: when the multipart `file` field is optional (as in the petstore spec), the generated handler does nothing on a missing file and proceeds to call `api.uploadFile(petId, null)`. Wrap the null-check in the template's `{{#required}}` section so it is only emitted with the `fail(400); return;` body, avoiding a misleading no-op for optional uploads.</comment>
<file context>
@@ -212,10 +212,11 @@ private void uploadFile(RoutingContext routingContext) {
+ .filter(upload -> "file".equals(upload.name()))
+ .findFirst()
+ .orElse(null);
+ if (_file == null) {
}
</file context>
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Fix multipart form file handling in Vert.x server generator to select uploads by field name, preventing wrong file mapping when multiple files or fields are present. Updated sample handlers and bumped
spring-webin a sample.Bug Fixes
JavaVertXWebServer/formParams.mustache, file params now filterroutingContext.fileUploads()by the form field name and return 400 when required and missing.PetApiHandlerimplementations to use the same logic.Dependencies
spring-webto7.0.8insamples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml.Written for commit 0e71892. Summary will update on new commits.