Skip to content

Fix multipart fields in vertx - #24668

Draft
wing328 wants to merge 1 commit into
masterfrom
vertx-followup
Draft

Fix multipart fields in vertx#24668
wing328 wants to merge 1 commit into
masterfrom
vertx-followup

Conversation

@wing328

@wing328 wing328 commented Aug 10, 2026

Copy link
Copy Markdown
Member

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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-web in a sample.

  • Bug Fixes

    • In JavaVertXWebServer/formParams.mustache, file params now filter routingContext.fileUploads() by the form field name and return 400 when required and missing.
    • Updated Vert.x sample PetApiHandler implementations to use the same logic.
  • Dependencies

    • Bump spring-web to 7.0.8 in samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml.

Written for commit 0e71892. Summary will update on new commits.

Review in cubic

@wing328 wing328 changed the title fix multipart fields in vertx Fix multipart fields in vertx Aug 10, 2026
@wing328
wing328 marked this pull request as ready for review August 10, 2026 10:47
@wing328 wing328 added this to the 7.25.0 milestone Aug 10, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Comment on lines +11 to 16
if ({{paramName}} == null) {
{{#required}}
routingContext.fail(400);
return;
{{/required}}
} else {
{{paramName}} = routingContext.fileUploads().iterator().next();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@wing328
wing328 marked this pull request as draft August 10, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant