fix(java): serialize JSON header parameter content - #25056
AndreyVMarkelov wants to merge 1 commit into
Conversation
21e592c to
3ae5d3e
Compare
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
fdf2b05 to
4c09a1c
Compare
|
@KannaKim @martin-mfg would you mind taking a look when you have a chance? This is a small Java client bug fix with regression coverage and green CI. This issue currently blocks our work on a new Dropbox SDK generated with OpenAPI Generator, so getting it into the next release would be very helpful. Thanks! |
There was a problem hiding this comment.
2 issues found across 15 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java">
<violation number="1" location="samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java:819">
P2: This helper is never used by the dynamic-operation header path, so JSON header parameters still serialize through `parameterToString(value)` and send generated model strings. Update `fillParametersFromOperation` to select `parameterToJsonString` for JSON content and retain `parameterToString` for other headers.</violation>
</file>
<file name="samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java">
<violation number="1" location="samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/ApiClient.java:804">
P3: `parameterToJsonString` always copies the whole `JSON.serialize` result into a second StringBuilder, even when the JSON contains no character >= 0x7f (the common case for header values such as `{"path":"/x"}`). Scan for a non-ASCII char first and return the JSON string unchanged when none is found, avoiding the allocation and full second pass.</violation>
</file>
There was a problem hiding this comment.
All reported issues were addressed across 19 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
1610ef6 to
1a5fbe0
Compare
Fixes #25055
Problem
For Java
okhttp-gsonclients, a header parameter defined using:was serialized through
ApiClient.parameterToString(...).For model objects, that produces the generated model's debug
toString()representation instead of JSON.Fix
\uXXXXfor ASCII-safe HTTP header values.parameterToString(...)behavior for non-JSON headers.Tests
Added:
DefaultCodegenregression coverage for JSON header parameter metadataokhttp-gsongeneration regression coverageVerified:
parameterToJsonString(...){"path":"/x"}is produced for ASCII input/тестis escaped as\uXXXXSummary by cubic
Fixes Java
okhttp-gsonclients sending JSON-content header parameters as the model's debugtoString()output instead of JSON, in both static and dynamic operations paths.CodegenParameterviaheaderIsJsonMimeType.parameterToJsonString(...)method, escaping non-ASCII characters as\uXXXXto keep HTTP headers ASCII-safe.contentforapplication/json.parameterToString(...)behavior.DefaultCodegen, generated-output, and sampleApiClientregression tests, plus an OpenAPI 3.1 fixture, and regenerates theokhttp-gsonsamples.Written for commit 1a5fbe0. Summary will update on new commits.