Skip to content

Bring Kotlin client code up-to-speed with changes#23188

Merged
4brunu merged 12 commits intoOpenAPITools:masterfrom
noordawod:feature/kotlin-client-finetuning
Mar 10, 2026
Merged

Bring Kotlin client code up-to-speed with changes#23188
4brunu merged 12 commits intoOpenAPITools:masterfrom
noordawod:feature/kotlin-client-finetuning

Conversation

@noordawod
Copy link
Contributor

@noordawod noordawod commented Mar 9, 2026

Looking at the generated Kotlin code from the most recent kotlin-client template, I saw a few warnings in the IDE about obsolete code. This PR brings the template up-to-speed with the latest Kotlin recommendations, and also removes an obsolete nullability check.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02)


Summary by cubic

Updates the kotlin-client JVM templates to modern Kotlin conventions, standardizes constants, and unifies base URL configuration with BASE_URL_KEY across okhttp, retrofit2, and vertx. Regenerates Kotlin samples and improves response and header handling.

  • Refactors
    • Converted header and media-type constants to UPPER_CASE and added @Deprecated aliases; introduced BASE_URL_KEY with a deprecated baseUrlKey alias across okhttp, retrofit2, and vertx.
    • Switched all generated APIs to read default base paths via BASE_URL_KEY (e.g., System.getProperties().getProperty(ApiClient.BASE_URL_KEY, ...)).
    • Fixed header constants and defaults: corrected ACCEPT/AUTHORIZATION values; default to application/json when missing.
    • Updated response handling: skip parsing for Unit; removed the obsolete null body check.
    • Removed unnecessary @JvmStatic annotations from constant declarations in retrofit2/vertx templates.

Written for commit 53460c7. Summary will update on new commits.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache:67">
P1: Header constants ACCEPT and AUTHORIZATION use uppercase values ("ACCEPT", "AUTHORIZATION") instead of canonical HTTP header names ("Accept", "Authorization"). This breaks case-sensitive map lookups since the generated API code sets headers using canonical casing ("Accept"), but ApiClient checks for uppercase keys ("ACCEPT"). This causes duplicate headers and can result in authentication issues when authorization headers are set with canonical casing.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

12 issues found across 103 files (changes from recent commits).

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:40">
P1: HTTP header constant values were incorrectly changed to uppercase strings. The constants ACCEPT and AUTHORIZATION have values "ACCEPT" and "AUTHORIZATION" instead of the canonical "Accept" and "Authorization". Since requestConfig.headers is a case-sensitive Kotlin Map, lookups will fail to match entries set with canonical header names, causing duplicate headers and auth/content-type conflicts.</violation>
</file>

<file name="samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Uppercased header-name constants can cause duplicate headers due to case-sensitive map lookups. HTTP headers like "Accept" and "Authorization" are commonly referenced with canonical casing, but the new constants use uppercase ("ACCEPT", "AUTHORIZATION"). Since Kotlin's Map uses case-sensitive key matching, lookups for "ACCEPT" will miss entries stored under "Accept", leading to duplicate/conflicting headers being sent to the server. Consider using canonical HTTP header names in the constants.</violation>
</file>

<file name="samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Header key constants changed to uppercase ("ACCEPT", "AUTHORIZATION") can break map-based header detection and cause duplicate/conflicting headers. HTTP headers are case-insensitive, but Kotlin map lookups are case-sensitive. If headers are set using conventional mixed-case keys (e.g., "Accept"), they won't be detected by uppercase key lookups, leading to duplicate headers with potentially conflicting values.</violation>
</file>

<file name="samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P2: Header constant values changed from standard Pascal-case ("Accept") to uppercase ("ACCEPT"), which breaks case-sensitive map lookups. Code using the standard "Accept" key won't be found, causing duplicate headers and potential request conflicts.</violation>
</file>

<file name="samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Header constants changed to uppercase values ("ACCEPT", "AUTHORIZATION") causing case-sensitive map lookup failures. Generated API code uses standard-cased keys ("Accept", "Authorization") but ApiClient now looks up with uppercase keys, resulting in missed lookups and duplicate/conflicting headers.</violation>
</file>

<file name="samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Case-changed header string constants can break case-sensitive `requestConfig.headers` lookups, potentially causing duplicate/conflicting Accept/Authorization headers when upstream code uses standard canonical header names.</violation>
</file>

<file name="samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:39">
P1: Header constants changed to uppercase strings breaks case-sensitive map lookups. When generated API code sets headers using canonical names (e.g., "Accept"), ApiClient lookups using "ACCEPT" won't find them, causing duplicate headers with conflicting keys.</violation>
</file>

<file name="samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Header constant values changed from standard casing to all-caps ("Accept" -> "ACCEPT") causing case-sensitive map lookup mismatches. Code setting headers with canonical names (e.g., `localVariableHeaders["Accept"]` in BirdApi.kt) won't be found when checked via `headers[ACCEPT]`, resulting in duplicate Accept headers being added unexpectedly.</violation>
</file>

<file name="samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Header key constants changed from canonical HTTP header names ("Accept", "Authorization") to uppercase versions ("ACCEPT", "AUTHORIZATION"). Since RequestConfig uses a case-sensitive MutableMap for headers, lookups using the new uppercase keys will not find headers that were set using the canonical names, potentially causing duplicate headers or auth failures.</violation>

<violation number="2" location="samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:106">
P2: Missing deprecated alias for renamed constant `baseUrlKey` -> `BASE_URL_KEY` breaks API compatibility inconsistently with other renamed constants</violation>
</file>

<file name="samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Case-sensitive header map lookups now use '"ACCEPT"' (all uppercase), which can ignore existing '"Accept"' entries stored by existing code. Kotlin MutableMap<String, String> is case-sensitive, so headers set with standard HTTP casing ('"Accept"') won't match lookups for '"ACCEPT"'. This can produce duplicate headers and override intended content negotiation.</violation>
</file>

<file name="samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:38">
P1: Header key constant values changed from canonical HTTP names to fully uppercase strings, creating case-sensitive Map lookup mismatches. The deprecated aliases now pass through uppercase values, potentially breaking existing code that sets headers using canonical casing (e.g., "Accept", "Authorization").</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

noordawod and others added 2 commits March 9, 2026 14:49
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var password: String? = null
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var accessToken: String? = null
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val baseUrlKey: String = "{{packageName}}.baseUrl"
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}const val BASE_URL_KEY: String = "{{packageName}}.baseUrl"
Copy link
Contributor

Choose a reason for hiding this comment

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

@noordawod why does this one don't have a Deprecated equivalent for migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks for spotting this ✅

{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object {
@JvmStatic
protected val baseUrlKey: String = "{{packageName}}.baseUrl"
protected val BASE_URL_KEY: String = "{{packageName}}.baseUrl"
Copy link
Contributor

Choose a reason for hiding this comment

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

@noordawod we should have a Deprecated equivalent for migration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

protected const val OctetMediaType: String = "application/octet-stream"
protected const val TextMediaType: String = "text/plain"
protected const val CONTENT_TYPE: String = "Content-Type"
protected const val ACCEPT: String = "ACCEPT"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
protected const val ACCEPT: String = "ACCEPT"
protected const val ACCEPT: String = "Accept"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

protected const val TextMediaType: String = "text/plain"
protected const val CONTENT_TYPE: String = "Content-Type"
protected const val ACCEPT: String = "ACCEPT"
protected const val AUTHORIZATION: String = "AUTHORIZATION"
Copy link
Contributor

Choose a reason for hiding this comment

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

protected const val AUTHORIZATION: String = "Authorization"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@noordawod noordawod requested review from 4brunu and Chrimle March 10, 2026 07:48
@4brunu
Copy link
Contributor

4brunu commented Mar 10, 2026

@noordawod Could you please take a look at CI failures? Thanks

@noordawod
Copy link
Contributor Author

@noordawod Could you please take a look at CI failures? Thanks

@4brunu Done, CI succeeds now 💪

@4brunu 4brunu merged commit a2fd144 into OpenAPITools:master Mar 10, 2026
68 checks passed
yonatankarp added a commit to yonatankarp/openapi-generator that referenced this pull request Mar 10, 2026
davidricodias pushed a commit to davidricodias/openapi-generator that referenced this pull request Mar 11, 2026
* Convert static constants to CAPITALS.

* Bring `responseBody` up-to-speed with regards to response nullability.

* Keep previous constants so not to break existing code.

* Generate samples code.

* Apply suggestion from @cubic-dev-ai[bot]

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Regenerate sample code.

* Reorder statics, fix values of `ACCEPT` and `AUTHORIZATION` constants.

* Regenerate sample code.

* Add deprecation constant.

* Regenerate sample code.

* Remove unnecessary annotation.

* Regenerate samples code.

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
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