-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[JAVA-SPRING] Convert byte[] to String for operation params [QueryParam; PathParam; HeaderParam; CookieParam; FormParam] #22930
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 41 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java">
<violation number="1" location="samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java:383">
P2: @RequestPart is for multipart/form-data, but this endpoint consumes application/x-www-form-urlencoded. The modified parameter still uses @RequestPart, so WebFlux won’t bind the form body correctly (likely 400).</violation>
</file>
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:944">
P2: Form/multipart DTO still asserts `format: byte` as `byte[]`, but Spring’s default data binding does not Base64‑decode form strings to `byte[]`; it converts the string to raw bytes. This makes form DTO binding inconsistent with the new `String` parameter handling and can yield incorrect values without a custom converter.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| @ApiParam(value = "None", required = true) @DecimalMin(value = "67.8") @DecimalMax(value = "123.4") @Valid @RequestPart(value = "double", required = true) Double _double, | ||
| @ApiParam(value = "None", required = true) @Pattern(regexp = "^[A-Z].*") @Valid @RequestPart(value = "pattern_without_delimiter", required = true) String patternWithoutDelimiter, | ||
| @ApiParam(value = "None", required = true) @Valid @RequestPart(value = "byte", required = true) byte[] _byte, | ||
| @ApiParam(value = "None", required = true) @Valid @RequestPart(value = "byte", required = true) String _byte /* base64 encoded binary */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: @RequestPart is for multipart/form-data, but this endpoint consumes application/x-www-form-urlencoded. The modified parameter still uses @RequestPart, so WebFlux won’t bind the form body correctly (likely 400).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-reactive-noResponseEntity/src/main/java/org/openapitools/api/FakeApi.java, line 383:
<comment>@RequestPart is for multipart/form-data, but this endpoint consumes application/x-www-form-urlencoded. The modified parameter still uses @RequestPart, so WebFlux won’t bind the form body correctly (likely 400).</comment>
<file context>
@@ -380,7 +380,7 @@ default Mono<Void> testEndpointParameters(
@ApiParam(value = "None", required = true) @DecimalMin(value = "67.8") @DecimalMax(value = "123.4") @Valid @RequestPart(value = "double", required = true) Double _double,
@ApiParam(value = "None", required = true) @Pattern(regexp = "^[A-Z].*") @Valid @RequestPart(value = "pattern_without_delimiter", required = true) String patternWithoutDelimiter,
- @ApiParam(value = "None", required = true) @Valid @RequestPart(value = "byte", required = true) byte[] _byte,
+ @ApiParam(value = "None", required = true) @Valid @RequestPart(value = "byte", required = true) String _byte /* base64 encoded binary */,
@ApiParam(value = "None") @Min(value = 10) @Max(value = 100) @Valid @RequestPart(value = "integer", required = false) Integer integer,
@ApiParam(value = "None") @Min(value = 20) @Max(value = 200) @Valid @RequestPart(value = "int32", required = false) Integer int32,
</file context>
| JavaFileAssert.assertThat(files.get("FormParamsRequest.java")) | ||
| .assertProperty("_byte") | ||
| .isArray() | ||
| .withType("byte"); // Base64 property in DTO → auto-decoded to byte[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Form/multipart DTO still asserts format: byte as byte[], but Spring’s default data binding does not Base64‑decode form strings to byte[]; it converts the string to raw bytes. This makes form DTO binding inconsistent with the new String parameter handling and can yield incorrect values without a custom converter.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 944:
<comment>Form/multipart DTO still asserts `format: byte` as `byte[]`, but Spring’s default data binding does not Base64‑decode form strings to `byte[]`; it converts the string to raw bytes. This makes form DTO binding inconsistent with the new `String` parameter handling and can yield incorrect values without a custom converter.</comment>
<file context>
@@ -864,6 +864,92 @@ public void testSchemaImplements() throws IOException {
+ JavaFileAssert.assertThat(files.get("FormParamsRequest.java"))
+ .assertProperty("_byte")
+ .isArray()
+ .withType("byte"); // Base64 property in DTO → auto-decoded to byte[]
+
+ // Binary request body: bound as Resource for streaming
</file context>
This change updates the generator to correctly map OpenAPI
format: bytefields across all locations.format: byteis generated asString(manual Base64 decoding required).String.format: binary):MultipartFile.byte[], with automatic Base64 decoding via Jackson.application/octet-stream):Resourcefor streaming, no decoding applied.This ensures all
format: bytevalues are correctly typed across parameters and bodies, preserving the distinction between Base64-encoded values and raw binary.The changes are practically limited to
QueryParam; PathParam; HeaderParam; CookieParam; FormParam. But all the other types are asserted as well to prevent accidental regression.fixes #22898
Tests performed:
Verified generated Java files for query, path, header, cookie, form, multipart, JSON body, and binary body fields.
Asserts confirm parameters and properties have the expected types (String, byte[], MultipartFile, Resource).
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Convert byte[] operation parameters to String in the Java Spring generator for query, path, header, cookie, and form params. Spring doesn’t auto-decode base64 for these, so we now accept the raw base64 string to prevent type issues.
Bug Fixes
Migration
Written for commit 02a530a. Summary will update on new commits.