Conversation
…ithub.com/rlnt/openapi-generator into rlnt-kotlin-client/integer-enums-multiplatform
There was a problem hiding this comment.
4 issues found across 36 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/enum_class.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache:187">
P3: Use `entries` instead of `values()` in enum deserialization to avoid per-call array allocation.</violation>
</file>
<file name="samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/models/CodeTest.kt">
<violation number="1" location="samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/models/CodeTest.kt:24">
P2: This test file currently has no actual test case, so it does not validate integer enum behavior.</violation>
</file>
<file name="samples/client/petstore/kotlin-enum-integers-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">
<violation number="1" location="samples/client/petstore/kotlin-enum-integers-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:23">
P1: The public primary constructor allows creating `ApiClient` without initializing `client`, which can crash at runtime with `UninitializedPropertyAccessException`.</violation>
</file>
<file name="samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt">
<violation number="1" location="samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt:30">
P2: This test case is empty, so it always passes and provides no coverage for the behavior it is named to validate.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| import org.openapitools.client.auth.* | ||
|
|
||
| open class ApiClient( |
There was a problem hiding this comment.
P1: The public primary constructor allows creating ApiClient without initializing client, which can crash at runtime with UninitializedPropertyAccessException.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/kotlin-enum-integers-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt, line 23:
<comment>The public primary constructor allows creating `ApiClient` without initializing `client`, which can crash at runtime with `UninitializedPropertyAccessException`.</comment>
<file context>
@@ -0,0 +1,188 @@
+
+import org.openapitools.client.auth.*
+
+open class ApiClient(
+ private val baseUrl: String
+) {
</file context>
| import org.openapitools.client.models.Code | ||
|
|
||
| class CodeTest : ShouldSpec() { | ||
| init { |
There was a problem hiding this comment.
P2: This test file currently has no actual test case, so it does not validate integer enum behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/models/CodeTest.kt, line 24:
<comment>This test file currently has no actual test case, so it does not validate integer enum behavior.</comment>
<file context>
@@ -0,0 +1,29 @@
+import org.openapitools.client.models.Code
+
+class CodeTest : ShouldSpec() {
+ init {
+ // uncomment below to create an instance of Code
+ //val modelInstance = Code()
</file context>
| //val apiInstance = DefaultApi() | ||
|
|
||
| // to test doGet | ||
| should("test doGet") { |
There was a problem hiding this comment.
P2: This test case is empty, so it always passes and provides no coverage for the behavior it is named to validate.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/kotlin-enum-integers-multiplatform/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt, line 30:
<comment>This test case is empty, so it always passes and provides no coverage for the behavior it is named to validate.</comment>
<file context>
@@ -0,0 +1,37 @@
+ //val apiInstance = DefaultApi()
+
+ // to test doGet
+ should("test doGet") {
+ // uncomment below to test doGet
+ //val result : DoGet200Response = apiInstance.doGet()
</file context>
|
|
||
| override fun deserialize(decoder: Decoder): {{classname}} { | ||
| val value = decoder.decodeSerializableValue({{{dataType}}}.serializer()) | ||
| return {{classname}}.values().firstOrNull { it.value == value } |
There was a problem hiding this comment.
P3: Use entries instead of values() in enum deserialization to avoid per-call array allocation.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache, line 187:
<comment>Use `entries` instead of `values()` in enum deserialization to avoid per-call array allocation.</comment>
<file context>
@@ -172,3 +177,20 @@ internal object {{classname}}Serializer : KSerializer<{{classname}}> {
+
+ override fun deserialize(decoder: Decoder): {{classname}} {
+ val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
+ return {{classname}}.values().firstOrNull { it.value == value }
+ ?: throw IllegalArgumentException("Unknown enum value: $value")
+ }
</file context>
| return {{classname}}.values().firstOrNull { it.value == value } | |
| return {{classname}}.entries.firstOrNull { it.value == value } |
based on #21983 and added a test to cover integer enums
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)
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)Summary by cubic
Adds a custom
kotlinx.serializationserializer for non-string enums in the Kotlin Multiplatform client so integer/number enums encode and decode correctly. This fixes incorrect handling of numeric enums in multiplatform builds.{{classname}}Serializerfor non-string enums that uses the underlying{{dataType}}.serializer()and maps byvalue.@Serializable(with = ...); apply@SerialNameonly for string enums.kotlinx.serializationimports (Decoder,Encoder,builtins.serializer).Written for commit 96c5385. Summary will update on new commits.