fix(kotlin-client): read API class properties through this. in jvm-volley
Follow-up to #25691, same approach for jvm-volley.
The jvm-volley API classes read their own properties requestFactory, basePath, postProcessors and requestQueue without this.. In Kotlin a function parameter hides a class property with the same name, so a spec parameter with one of these names replaces the property inside that operation. On master, jvm-volley generates:
val request: Request<Unit> = requestFactory.build(
Request.Method.GET,
"$basePath$path",
...
postProcessors.forEach { it.invoke(request) }
requestQueue.value.add(request)
- With a parameter named
basePath, the request goes to the parameter's value instead of the configured base path. This fails silently. - With a parameter named
requestFactory,postProcessorsorrequestQueue, the generated code does not compile. I checkedrequestFactorywithkotlinc(unresolved reference 'build').
Fix
jvm-volley/api.mustache now reads the four properties through this.:
this.requestFactory.build("${this.basePath}$path"this.postProcessors.forEachthis.requestQueue.value.add
All four are directly inside the receiver-less suspendCoroutine { continuation -> ... } lambda, so this is the API class. They are outside the Response.Listener / Response.ErrorListener lambdas. I compiled and ran the same shape with kotlinc: with a parameter basePath = "http://WRONG", the qualified version uses the property "http://localhost".
The fifth property, context, is only read in the constructor's default value for requestQueue, where operation parameters are not in scope, so it cannot collide.
Parameters keep their names; the generated signatures do not change.
Not covered here
The operation's own locals can also collide with parameter names: body, contentTypes, contentType, path, formParams, queryParams and headerParams. For example, a query parameter named path sends the URL path as its value. Neither this PR, #25691 nor #25690 renames them. Renaming them touches lines that #25690's test asserts and that #25625 changes, so I'd rather do it after those are settled.
Relation to other open PRs
- #25691 applies the same
this.qualification tojvm-vertx. The two PRs are independent, except that both add a test toKotlinClientCodegenApiTest. - #25625 changes lines 63ā85 of the same template (
escapeDollar), and this PR changes lines 98ā112. The template changes merge without conflict. - #25690 asserts other
jvm-volleylines and does not touch these four. Only the test file overlaps.
Whichever PR is merged later needs a rebase of the test file, which I will do.
Tests
KotlinClientCodegenApiTest.testJvmVolleyApiClassMembersAreThisQualified (new) generates jvm-volley (gson) from 3_0/kotlin/kotlin-volley-member-collision.yaml, whose query parameters are named after the properties. It checks:
- the four qualified lines, each as an exact, trimmed line;
- that none of the four property reads appears without
this.; - that the parameters are still sent under their own names.
./mvnw -nsu -Denforcer.skip=true -pl modules/openapi-generator -am -Dtest=KotlinClientCodegenApiTest -Dsurefire.failIfNoSpecifiedTests=false test
| Result | |
|---|---|
| master + this PR | 35 tests, 0 failures, 0 skipped |
| with the template change reverted | testJvmVolleyApiClassMembersAreThisQualified fails |
with only this.basePath removed | testJvmVolleyApiClassMembersAreThisQualified fails |
Samples
There is no bin/configs entry for the jvm-volley library, so no samples change. This also means CI does not compile jvm-volley output. The compile check above was done with kotlinc, on a class of the same shape, not on a generated client.
cc @wing328 and the Kotlin technical committee: @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l @AndreyVMarkelov
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples ā scoped to this change: there is no sample config for
jvm-volley, so there is nothing to regenerate.export_docs_generators.shnot run: no generator option or metadata changes.
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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.
š¤ Generated with Claude Code
Summary by cubic
Qualifies the jvm-volley API class property reads with this. so operation parameters no longer shadow them. On master, a query parameter named basePath silently replaces the configured base URL, and parameters named requestFactory, postProcessors, or requestQueue generate code that does not compile.
Parameter names and generated signatures are unchanged. context stays unqualified because it is only read in a constructor default value where operation parameters are not in scope.
Tests
- Adds
testJvmVolleyApiClassMembersAreThisQualified, which generates from a spec whose query parameters are named after the four properties and verifies the property reads are this-qualified while the parameters still reach the wire under their own names.