Bring Kotlin client code up-to-speed with changes#23188
Bring Kotlin client code up-to-speed with changes#231884brunu merged 12 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
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-aiwith guidance or docs links (includingllms.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.
...r/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
...tlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...otlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...petstore/kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...ent/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...tore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...fault-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...ho_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
...tore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
Outdated
Show resolved
Hide resolved
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" |
There was a problem hiding this comment.
@noordawod why does this one don't have a Deprecated equivalent for migration?
There was a problem hiding this comment.
Fixed, thanks for spotting this ✅
...r/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
Show resolved
Hide resolved
| {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}companion object { | ||
| @JvmStatic | ||
| protected val baseUrlKey: String = "{{packageName}}.baseUrl" | ||
| protected val BASE_URL_KEY: String = "{{packageName}}.baseUrl" |
There was a problem hiding this comment.
@noordawod we should have a Deprecated equivalent for migration
...or/src/main/resources/kotlin-client/libraries/jvm-vertx/infrastructure/ApiClient.kt.mustache
Show resolved
Hide resolved
| 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" |
There was a problem hiding this comment.
| protected const val ACCEPT: String = "ACCEPT" | |
| protected const val ACCEPT: String = "Accept" |
| 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" |
There was a problem hiding this comment.
protected const val AUTHORIZATION: String = "Authorization"
...r/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
Show resolved
Hide resolved
|
@noordawod Could you please take a look at CI failures? Thanks |
@4brunu Done, CI succeeds now 💪 |
Picks up constant renaming from upstream (OpenAPITools#23188).
* 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>
Looking at the generated Kotlin code from the most recent
kotlin-clienttemplate, 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
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)@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-clientJVM templates to modern Kotlin conventions, standardizes constants, and unifies base URL configuration withBASE_URL_KEYacrossokhttp,retrofit2, andvertx. Regenerates Kotlin samples and improves response and header handling.@Deprecatedaliases; introducedBASE_URL_KEYwith a deprecatedbaseUrlKeyalias acrossokhttp,retrofit2, andvertx.BASE_URL_KEY(e.g.,System.getProperties().getProperty(ApiClient.BASE_URL_KEY, ...)).ACCEPT/AUTHORIZATIONvalues; default toapplication/jsonwhen missing.Unit; removed the obsolete null body check.@JvmStaticannotations from constant declarations inretrofit2/vertxtemplates.Written for commit 53460c7. Summary will update on new commits.