Skip to content

fix(kotlin-server): use valid Kotlin String conversions for ktor delegate header params#24218

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-24214-kotlin-server-ktor-header-param-conversion
Jul 7, 2026
Merged

fix(kotlin-server): use valid Kotlin String conversions for ktor delegate header params#24218
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-24214-kotlin-server-ktor-header-param-conversion

Conversation

@seonwooj0810

@seonwooj0810 seonwooj0810 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #24214

Root cause

The ktor delegatePattern header-extraction template (kotlin-server/libraries/ktor/_extract_param_value.mustache, added in #23756) converts a raw header String with it.to{{{dataType}}}(), interpolating the fully-qualified Kotlin type. For a non-string/enum header this produces uncompilable Kotlin, e.g. a boolean header generates it.tokotlin.Boolean() and a number header generates it.tojava.math.BigDecimal(). The endpoint's generated code therefore does not compile. Query/path params are unaffected because they go through ktor typed routing.

Change

Kotlin's String conversion functions use the simple type name, not the FQN. The template now maps the primitive type flags to the correct stdlib functions:

header type before (broken) after
boolean it.tokotlin.Boolean() it.toBoolean()
integer (int32) it.tokotlin.Int() it.toInt()
integer (int64) it.tokotlin.Long() it.toLong()
number/double it.tokotlin.Double() it.toDouble()
number (BigDecimal) it.tojava.math.BigDecimal() it.toBigDecimal()

string/enum headers are unchanged. Types outside this set (e.g. UUID, date-time) keep the previous fallback, so the change is scoped to the reported primitive/number regression. The int32/isShort flag is deliberately not mapped to toShort() because isShort is set for format: int32 (which maps to kotlin.Int), and no schema type maps to kotlin.Short.

Tests

Added KotlinServerCodegenTest#delegatePattern_headerParamPrimitiveConversion, which generates a spec with boolean/int32/int64/double/number header params and asserts the generated conversions are it.toBoolean()/it.toInt()/it.toLong()/it.toDouble()/it.toBigDecimal(), and that the old it.tokotlin.Boolean()/it.tojava.math.BigDecimal() forms are gone. Fails before the fix, passes after.

Verification done

  • Reproduced on latest master via the CLI (-g kotlin-server --library ktor --additional-properties delegatePattern=true): boolean/numeric header params emitted uncompilable it.to<FQN>(); confirmed corrected output after the change.
  • ./mvnw -pl modules/openapi-generator test -Dtest=KotlinServerCodegenTest — all 26 tests pass (JDK 21).
  • Confirmed the change produces no diff in the committed kotlin-server-ktor-delegate-pattern sample (petstore has no boolean/numeric header params), so no sample regeneration is required.

Summary by cubic

Fixes invalid header param conversions in the kotlin-server generator when using ktor delegate pattern. Generated code now uses Kotlin String extension functions so header parsing compiles correctly.

  • Bug Fixes
    • Map header conversions to valid Kotlin functions: boolean → toBoolean(), int32 → toInt(), int64 → toLong(), double → toDouble(), unformatted number (BigDecimal) → toBigDecimal().
    • Leave string/enum headers and non-primitive types unchanged; fallback remains for others.
    • Added a regression test to verify correct conversions and remove it.to<fully.qualified.DataType>() usages. Fixes [BUG][kotlin-server] Description #24214.

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

Review in cubic

…gate header params

The ktor delegate-pattern header extraction template emitted
it.to<fully.qualified.DataType>() (e.g. it.tokotlin.Boolean(),
it.tojava.math.BigDecimal()), which is not valid Kotlin and fails to
compile. Kotlin's String conversion functions use the simple type name
(toBoolean/toInt/toLong/toDouble/toBigDecimal), so map the primitive
type flags to those functions instead of interpolating the dataType.

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.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 3 files

Re-trigger cubic

@wing328

wing328 commented Jul 7, 2026

Copy link
Copy Markdown
Member

thanks for the PR

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

@seonwooj0810

Copy link
Copy Markdown
Contributor Author

Thanks @wing328! Happy to iterate on any reviewer feedback — just let me know if anything needs adjusting.

@wing328

wing328 commented Jul 7, 2026

Copy link
Copy Markdown
Member

let's give it a try

thanks for the contribution.

@wing328 wing328 merged commit 27122af into OpenAPITools:master Jul 7, 2026
15 checks passed
@Frontrider

Copy link
Copy Markdown
Contributor

thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][kotlin-server] Description

3 participants