Repository navigation
fix(kotlin-client): keep deepObject wire keys parameter-local and baseName-based - #25622
Merged
wing328 merged 3 commits intoNov 11, 2026
Merged
Conversation
…eName-based
Two deepObject bugs in the kotlin-client query serialization:
1. propagateParamBaseNameToVars wrote x-kotlin-param-base-name onto
CodegenProperty instances that come from DefaultCodegen.fromProperty()'s
cache, so two deepObject parameters sharing a model/property overwrote
each other's wire-key prefix. With `filter-a` and `filter-b` sharing one
schema, jvm-ktor emitted `localVariableQuery["filter-b[field]"]` for BOTH
parameters. Vars are now cloned before the parameter-local extension is
attached.
2. jvm-okhttp built the deepObject wire key from paramName
(`put("filterA[field]")`), so hyphenated/renamed parameters sent a key
that does not match the spec baseName. The template now uses the same
x-kotlin-param-base-name extension as jvm-ktor, so the key is
`filter-a[field]` regardless of the Kotlin identifier.
New fixture kotlin-deepobject-shared-vars.yaml + a jvm-ktor/jvm-okhttp4
test asserting each parameter keeps its own baseName on the wire.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The deepObject wire key now uses the spec baseName (query_object) instead of the camelized paramName (queryObject). Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review findings on the shared-vars fix:
- Rename the fixture property `field` to `status`: `field` is a Kotlin
keyword, so the generated accessor is backticked and `{{name}}`
interpolations emit the HTML-escaped `` `field` `` in jvm-okhttp,
which cannot compile (a pre-existing template bug, out of scope here).
- Assert the generated key/value pairs, not just the keys: the
jvm-okhttp4 `put("filter-a[status]", listOf(filterA.status.toString()))`
and jvm-ktor `localVariableQuery["filter-a[status]"]` lines now verify
that each wire key reads its own parameter's property.
- Render the `x-kotlin-param-base-name` prefix with triple braces (like
`{{{paramName}}}`) in the three jvm-okhttp put() sites so parameter
names containing `'` or `&` are not HTML-escaped in the wire key.
The regenerated kotlin-jvm-okhttp-echo-api sample is byte-identical.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 11, 2026
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two bugs in how the
kotlinclient builds query keys forstyle: deepObjectparameters. In both, the key put on the wire does not match the parameter name declared in the spec.KotlinClientCodegen.propagateParamBaseNameToVarswritesx-kotlin-param-base-nameonto eachCodegenPropertyinparam.vars. Those property instances come fromDefaultCodegen.fromProperty()'s cache, so two deepObject parameters that use the same schema share them, and the parameter processed last overwrites the prefix of the other.jvm-okhttp/api.mustache(the template behindlibrary=jvm-okhttp4) builds the key from{{{paramName}}}(camelized), so a parameter declared asquery_objectis sent asqueryObject[id].Reproducer
modules/openapi-generator/src/test/resources/3_0/kotlin/kotlin-deepobject-shared-vars.yaml(added by this PR): two deepObject query parameters,filter-aandfilter-b, both$ref: '#/components/schemas/Filter'(one string propertystatus).On master:
jvm-ktoremitslocalVariableQuery["filter-b[status]"]for both parameters, so thefilter-avalue is sent underfilter-b[status].jvm-okhttp4emitsput("filterA[status]", …)andput("filterB[status]", …). Neither key matches the declared namesfilter-a/filter-b.With this PR, both libraries emit
filter-a[status]forfilter-aandfilter-b[status]forfilter-b.The existing
echo_apisample shows bug 2 on a real spec.samples/client/echo_api/kotlin-jvm-okhttp/.../QueryApi.ktsendsqueryObject[id],queryObject[name], … for the parameter declared asquery_object. After regeneration it sendsquery_object[id],query_object[name], ….Fix
propagateParamBaseNameToVarsclones each var (CodegenProperty.clone()) before attaching the parameter-local extension, and assigns the copies toparam.vars. The cached instances are no longer modified.jvm-okhttp/api.mustache: the threeput("…[…]")sites use{{{vendorExtensions.x-kotlin-param-base-name}}}(throughlambda.escapeDollar, as the property part already does), the same source jvm-ktor uses. Triple braces keep the name unescaped, as{{{paramName}}}did before.Behavior change
For jvm-okhttp clients, the query key of a deepObject parameter whose spec name differs from its Kotlin identifier changes from the identifier to the spec name, e.g.
queryObject[id]→query_object[id]. The new key is what the spec declares. A server that only accepted the old key would see different keys after regenerating the client.Tests
testDeepObjectParamsKeepOwnWireKeyPrefix(new)jvm-ktor,jvm-okhttp4filterA?.status?.let { localVariableQuery["filter-a[status]"] = listOf("$it") }(jvm-ktor) andput("filter-a[status]", listOf(filterA.status.toString()))(jvm-okhttp4), and the same forfilter-b./mvnw -nsu -Denforcer.skip=true -pl modules/openapi-generator -am -Dtest=KotlinClientCodegenApiTest -Dsurefire.failIfNoSpecifiedTests=false testKotlinClientCodegen.javaandapi.mustachechanges reverted (tests kept; only the new test run)testDeepObjectParamsKeepOwnWireKeyPrefixSamples
Only
samples/client/echo_api/kotlin-jvm-okhttpchanged (1 file,QueryApi.kt, the keys shown above). It is built bysamples-kotlin-echo-api.yaml.This PR and its sibling PRs #25623, #25624 and #25625 (
$escaping in wire names) all touchKotlinClientCodegenApiTestand neighboring kotlin-client templates; whichever merges first, I will rebase the others.cc @wing328 @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l (Kotlin technical committee)
PR checklist
./mvnw -pl modules/openapi-generator-cli -am package -DskipTests) and regenerated the affected kotlin configs with./bin/generate-samples.sh; the resulting diff is committed.export_docs_generators.shnot run: no generator option or metadata changes.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.
🤖 Generated with Claude Code