Skip to content

fix(kotlin-client): read ApiClient properties through this. in jvm-vertx - #25691

Open
khayashi4337 wants to merge 5 commits into
OpenAPITools:masterfrom
khayashi4337:fix/kotlin-vertx-member-qualify
Open

khayashi4337 wants to merge 5 commits into
OpenAPITools:masterfrom
khayashi4337:fix/kotlin-vertx-member-qualify

Conversation

@khayashi4337

@khayashi4337 khayashi4337 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

The jvm-vertx API classes extend ApiClient and read its properties (basePath, accessToken, apiKey, apiKeyPrefix, username, password, vertx) 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 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-vertx generates for example:

fun basicOpWithHttpInfo(username: kotlin.String?, password: kotlin.String?) : Future<ApiResponse<Unit?>> {
    val vertxClient = WebClient.create(vertx)
    val request = vertxClient.requestAbs(HttpMethod.GET, UriTemplate.of("$basePath/basic"))
    ...
    username?.let { username ->
        password?.let { password ->
            request.basicAuthentication(username, password)

I compiled and ran the same shapes with kotlinc:

  • the basic credentials sent are the values of the username and password parameters, not the client's;
  • a basePath parameter replaces the base URL;
  • an apiKey parameter (a String?) makes apiKey["X-API-KEY"] fail to compile.

Fix

jvm-vertx/api.mustache now reads these properties through this.:

  • WebClient.create(this.vertx) and "${this.basePath}{{{path}}}";
  • this.apiKey[...] and this.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

Relation to other open PRs

Tests

KotlinClientCodegenApiTest.testJvmVertxApiClientMembersAreThisQualified (new) generates jvm-vertx from the spec above. It checks two things:

  • every property read listed under Fix appears with this., matched as an exact, trimmed line, for each auth branch;
  • no line reads one of the seven properties without 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 test

Result
master + this PR 35 tests, 0 failures, 0 skipped
with the template change reverted testJvmVertxApiClientMembersAreThisQualified fails
with only one this. removed (apiKeyPrefix, OAuth accessToken, or the query API key) testJvmVertxApiClientMembersAreThisQualified fails in each case

Samples

Regenerated bin/configs/kotlin-*. Only the four jvm-vertx samples (kotlin-jvm-vertx-gson, -jackson, -jackson-coroutines, -moshi) change, in PetApi.kt, StoreApi.kt and UserApi.kt (12 files). Each changed line only gains this.. 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

  • Read the contribution guidelines.
  • Run the following to build the project and update samples — scoped to this change: built the CLI (./mvnw -pl modules/openapi-generator-cli -am package -DskipTests) and regenerated bin/configs/kotlin-* with ./bin/generate-samples.sh; the four jvm-vertx samples are committed. export_docs_generators.sh not run: no generator option or metadata changes.
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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

Fixes a bug in generated jvm-vertx Kotlin clients where an operation parameter with the same name as an ApiClient property (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 ApiClient member reads in the library template are now this.-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 in jvm-volley and is not addressed here.

Written for commit 3503501. Summary will update on new commits.

View guided diff

khayashi4337 and others added 3 commits November 16, 2026 05:30
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>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 15 files

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 30, 2026

Copy link
Copy Markdown
Member

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>
@khayashi4337

Copy link
Copy Markdown
Contributor Author

Thanks for the tip. I merged master and resolved the conflict in KotlinClientCodegenApiTest. The jvm-volley test from master stays as it is, and the jvm-vertx test now sits in the middle of the file (before testJvmKtorQueryParamWithTypeObject) instead of at the end. No other file changed. KotlinClientCodegenApiTest passes locally (36 tests), and regenerating the kotlin-* samples gives no diff.

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>
@khayashi4337

Copy link
Copy Markdown
Contributor Author

Heads-up: this PR and #25625 both change the same lines of kotlin-client/libraries/jvm-vertx/api.mustache (the requestAbs(...) line and the API key branches), so whichever is merged second will conflict. The two changes are compatible: #25625 wraps the names in lambda.escapeDollar, and this PR reads the client properties through this.. Whichever is merged first, I will merge master into the other one, combine both changes, and regenerate the jvm-vertx samples.

(I also pushed an empty commit to re-run CI: the previous kotlin-multiplatform sample build failed because it could not download yarn, which is unrelated to this change.)

khayashi4337 added a commit to khayashi4337/openapi-generator that referenced this pull request Dec 1, 2026
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>
@khayashi4337

Copy link
Copy Markdown
Contributor Author

Note: the failing check Build Kotlin client (samples/client/petstore/kotlin-enum-integers-multiplatform) is unrelated to this PR — the failure is a dependency resolution error (Could not resolve com.yarnpkg:yarn:1.22.22) in a multiplatform sample, while this PR only touches the jvm-vertx template/tests. A re-run should clear it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants