Repository navigation
fix(kotlin-client): read ApiClient properties through this. in jvm-vertx - #25691
khayashi4337 wants to merge 5 commits into
Conversation
In the jvm-vertx library, generated API classes referenced ApiClient properties (basePath, accessToken, apiKey, apiKeyPrefix, username, password, vertx) unqualified inside *WithHttpInfo functions. An operation parameter with the same name shadowed the member, so the client sent the parameter value as the credential/URL (and apiKey collisions did not even compile). Qualify all member references with this.; spec parameters stay unqualified and still reach the wire. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…qualification test Extend kotlin-vertx-member-collision.yaml with an apiKey-in-query scheme and an oauth2 clientCredentials scheme so every auth branch in the jvm-vertx api template is exercised. Assert every qualified apiKey/apiKeyPrefix line for both header and query delivery, require two qualified accessToken blocks (bearer + oauth), and scan the whole generated file for any unqualified member reference shape. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
please resolve the merge conflicts when you've time. (moving forward, you may want to randomly add some where in the test file as putting the new tests at the end likely result in merge conflicts with other PRs that also try to add tests to the end of the file) |
…member-qualify Resolve the conflict in KotlinClientCodegenApiTest by keeping both the jvm-volley test from master and the jvm-vertx test, which now sits in the middle of the file instead of at the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the tip. I merged master and resolved the conflict in |
The previous run failed outside this change: the kotlin-multiplatform sample build could not download yarn. Only maintainers can re-run the jobs, so this empty commit triggers a new run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Heads-up: this PR and #25625 both change the same lines of (I also pushed an empty commit to re-run CI: the previous |
The following fixes were extracted into separate PRs and no longer belong here; revert them to upstream/master so that this PR now only carries the OpenAPI 3.2 changes. | fix | what | original commits | split-out PR | |-----|------|------------------|--------------| | A1 | kotlin jvm-vertx form sending | parts of 75be8f4, 7f1bcb8 | OpenAPITools#25623 | | A2 | kotlin ktor/multiplatform form `it` | parts of 07530ab, 3a953e5, f1575f3, 7f1bcb8 | OpenAPITools#25624 | | A3 | kotlin `$` escaping | parts of 9074531, 7f1bcb8 | OpenAPITools#25625 | | A4 | kotlin member reads via `this.` | 94aca3a, 19694ac (main part) | OpenAPITools#25691, OpenAPITools#25692 | | A5 | kotlin param/generated-local collisions | rename part of 6b82674 | OpenAPITools#25690 | | A6 | kotlin deepObject keys | 910b590 | OpenAPITools#25622 | | A7 | core form required (allOf) | 7ab9da5, bc20a2c | OpenAPITools#25627 | | A8 | php internal-variable collisions | 9f2676e, a00d51c (keeping the 3.2 capture/fixture parts) | OpenAPITools#25630 | | A9 | csharp webhook input models | webhook-scan part of e49e09e | OpenAPITools#25626 | | A10 | core unexpected-attribute regex | widen part of e5ec5f4 | OpenAPITools#25621 | This PR now only carries the OpenAPI 3.2 changes. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note: the failing check |
The
jvm-vertxAPI classes extendApiClientand read its properties (basePath,accessToken,apiKey,apiKeyPrefix,username,password,vertx) withoutthis.. In Kotlin a function parameter hides a class property with the same name, so a spec parameter with one of these names replaces the client's value inside that operation.Reproducer
modules/openapi-generator/src/test/resources/3_0/kotlin/kotlin-vertx-member-collision.yaml(added by this PR) has operations with basic, bearer, OAuth2 and API key (header and query) security, and query parameters named after the properties. On master,jvm-vertxgenerates for example:I compiled and ran the same shapes with
kotlinc:usernameandpasswordparameters, not the client's;basePathparameter replaces the base URL;apiKeyparameter (aString?) makesapiKey["X-API-KEY"]fail to compile.Fix
jvm-vertx/api.mustachenow reads these properties throughthis.:WebClient.create(this.vertx)and"${this.basePath}{{{path}}}";this.apiKey[...]andthis.apiKeyPrefix[...]in the API key branches;this.username?.let { username -> this.password?.let { password -> ... } };this.accessToken?.let { accessToken -> ... }for bearer and OAuth.The parameters keep their names, so the generated signatures do not change. Only the property reads change.
Not covered here
responseBody(...),handleResponse(...),encodeURIComponent(...),parseDateToQueryString(...),toMultiValue(...),collectionDelimiter(...)) are left as they are. Kotlin resolves a call to the function even when a value parameter has the same name; I checked this withkotlinc.jvm-vertx(vertxClient,request,form) can also collide with parameters. A body parameter namedrequest, for example, makes.sendBuffer(responseBody(request))read the local. Neither this PR nor fix(kotlin-client): rename parameters that collide with template locals #25690 (which renames parameters that collide withlocalVariable*locals in five other libraries) handles them. Renaming them touches the same lines as fix(kotlin-client): rename parameters that collide with template locals #25690's and fix(kotlin-client): actually send the jvm-vertx form body #25623's tests, so I'd rather do it after those are settled.jvm-volleyhas the same pattern: the propertiesbasePath,requestFactory,postProcessorsandrequestQueueare read withoutthis.. This needs a separate change.Relation to other open PRs
KotlinClientCodegenand does not rename anything injvm-vertx. The two PRs only meet inKotlinClientCodegenApiTest.jvm-vertxform bodies) changes other lines of the same template; the two template changes merge without conflict. The test file and thejvm-vertxsamples overlap. Whichever PR is merged second needs a rebase and a sample regeneration, which I will do.Tests
KotlinClientCodegenApiTest.testJvmVertxApiClientMembersAreThisQualified(new) generatesjvm-vertxfrom the spec above. It checks two things:this., matched as an exact, trimmed line, for each auth branch;this..The same parameters are still sent as query parameters under their own names.
./mvnw -nsu -Denforcer.skip=true -pl modules/openapi-generator -am -Dtest=KotlinClientCodegenApiTest -Dsurefire.failIfNoSpecifiedTests=false testtestJvmVertxApiClientMembersAreThisQualifiedfailsthis.removed (apiKeyPrefix, OAuthaccessToken, or the query API key)testJvmVertxApiClientMembersAreThisQualifiedfails in each caseSamples
Regenerated
bin/configs/kotlin-*. Only the fourjvm-vertxsamples (kotlin-jvm-vertx-gson,-jackson,-jackson-coroutines,-moshi) change, inPetApi.kt,StoreApi.ktandUserApi.kt(12 files). Each changed line only gainsthis.. I have not compiled the samples locally; the existing Kotlin client sample workflow builds them.cc @wing328 and the Kotlin technical committee: @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l @AndreyVMarkelov
PR checklist
./mvnw -pl modules/openapi-generator-cli -am package -DskipTests) and regeneratedbin/configs/kotlin-*with./bin/generate-samples.sh; the fourjvm-vertxsamples are 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
Summary by cubic
Fixes a bug in generated
jvm-vertxKotlin clients where an operation parameter with the same name as anApiClientproperty (basePath,accessToken,apiKey,apiKeyPrefix,username,password,vertx) shadowed the client's value, causing wrong credentials or URLs to be sent and API key collisions to fail compilation.All
ApiClientmember reads in the library template are nowthis.-qualified. Spec parameters keep their names, so generated signatures are unchanged. A regression test covers basic, bearer, OAuth2, and header and query API key branches; the same shadowing also exists injvm-volleyand is not addressed here.Written for commit 3503501. Summary will update on new commits.