fix(kotlin-server): use valid Kotlin String conversions for ktor delegate header params#24218
Merged
wing328 merged 1 commit intoJul 7, 2026
Conversation
…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>
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) |
Contributor
Author
|
Thanks @wing328! Happy to iterate on any reviewer feedback — just let me know if anything needs adjusting. |
Member
|
let's give it a try thanks for the contribution. |
Contributor
|
thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24214
Root cause
The ktor
delegatePatternheader-extraction template (kotlin-server/libraries/ktor/_extract_param_value.mustache, added in #23756) converts a raw headerStringwithit.to{{{dataType}}}(), interpolating the fully-qualified Kotlin type. For a non-string/enum header this produces uncompilable Kotlin, e.g. abooleanheader generatesit.tokotlin.Boolean()and anumberheader generatesit.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
Stringconversion functions use the simple type name, not the FQN. The template now maps the primitive type flags to the correct stdlib functions:it.tokotlin.Boolean()it.toBoolean()it.tokotlin.Int()it.toInt()it.tokotlin.Long()it.toLong()it.tokotlin.Double()it.toDouble()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. Theint32/isShortflag is deliberately not mapped totoShort()becauseisShortis set forformat: int32(which maps tokotlin.Int), and no schema type maps tokotlin.Short.Tests
Added
KotlinServerCodegenTest#delegatePattern_headerParamPrimitiveConversion, which generates a spec with boolean/int32/int64/double/number header params and asserts the generated conversions areit.toBoolean()/it.toInt()/it.toLong()/it.toDouble()/it.toBigDecimal(), and that the oldit.tokotlin.Boolean()/it.tojava.math.BigDecimal()forms are gone. Fails before the fix, passes after.Verification done
mastervia the CLI (-g kotlin-server --library ktor --additional-properties delegatePattern=true): boolean/numeric header params emitted uncompilableit.to<FQN>(); confirmed corrected output after the change../mvnw -pl modules/openapi-generator test -Dtest=KotlinServerCodegenTest— all 26 tests pass (JDK 21).kotlin-server-ktor-delegate-patternsample (petstore has no boolean/numeric header params), so no sample regeneration is required.Summary by cubic
Fixes invalid header param conversions in the
kotlin-servergenerator when usingktordelegate pattern. Generated code now uses Kotlin String extension functions so header parsing compiles correctly.toBoolean(), int32 →toInt(), int64 →toLong(), double →toDouble(), unformatted number (BigDecimal) →toBigDecimal().it.to<fully.qualified.DataType>()usages. Fixes [BUG][kotlin-server] Description #24214.Written for commit adbd1be. Summary will update on new commits.