Skip to content

Conversation

jef
Copy link
Contributor

@jef jef commented Sep 10, 2025

Updated string and number parameter handling to ensure proper conversion to string before appending.

Fixes errors like this:

$ ./gradlew compileKotlin

// --snip--

generated-client-code/.../SomeApi.kt:100:50 Type mismatch: inferred type is BigDecimal but String was expected

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.

Updated string and number parameter handling to ensure proper conversion to string before appending.
@jef
Copy link
Contributor Author

jef commented Sep 10, 2025

Mentioning committee group based on PR template (thank you in advanced)

@dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10)

@@ -72,7 +72,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
{{{paramName}}}?.apply { append("{{{baseName}}}", {{{paramName}}}.toString()) }
{{/isNumber}}
{{#isNumber}}
{{{paramName}}}?.apply { append("{{{baseName}}}", {{{paramName}}}) }
{{{paramName}}}?.apply { append("{{{baseName}}}", {{{paramName}}}.toString()) }
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the PR

do we need to do a null check, i.e. {{{paramName}}}?.toString() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, let's add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up adding to to both of the .toString() methods.

@wing328
Copy link
Member

wing328 commented Sep 12, 2025

circleci failure not related to this change.

i'll add some tests later

thanks for the contribution

@wing328 wing328 merged commit 58fde20 into OpenAPITools:master Sep 12, 2025
13 of 14 checks passed
@wing328 wing328 added this to the 7.16.0 milestone Sep 12, 2025
@wing328
Copy link
Member

wing328 commented Sep 12, 2025

I added a test but got errors:

> Task :compileKotlin FAILED
e: file:///home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt:90:61 Type mismatch: inferred type is String? but String was expected
e: file:///home/runner/work/openapi-generator/openapi-generator/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt:91:63 Type mismatch: inferred type is String? but String was expected

ref: https://github.com/OpenAPITools/openapi-generator/actions/runs/17666370010/job/50208666016?pr=21952

can you please take a look ?

auto-generated test code: https://github.com/OpenAPITools/openapi-generator/pull/21952/files#diff-0a5b12edfc72d1712f3be5a8c8c1020063d76e2d40fa7fa6be634efeae7524c5R91

Ref PR: #21952

@wing328
Copy link
Member

wing328 commented Sep 12, 2025

I included a fix (a06a6ee) in that PR

Basically there seems to be no need for ? given that it's done earlier before .apply{}, e.g.

--- a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt
+++ b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt
@@ -87,8 +87,8 @@ import java.text.DateFormat
             val localVariableBody =
                         ParametersBuilder().also {
                         name?.apply { it.append("name", name) }
-                        status?.apply { it.append("status", status?.toString()) }
-                        status2?.apply { it.append("status2", status2?.toString()) }
+                        status?.apply { it.append("status", status.toString()) }
+                        status2?.apply { it.append("status2", status2.toString()) }
                         }.build()

@jef
Copy link
Contributor Author

jef commented Sep 12, 2025

I wish I had caught that earlier!

Thanks @wing328 for getting this across the finish line 😁

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.

2 participants