Repository navigation
Conversation
…is an inline enum A map property whose additionalProperties is an inline enum is flagged isEnum, and the kotlin and kotlin-spring data class property templates only special-cased arrays, so it was emitted as the bare nested enum instead of a Map. The templates now wrap the nested enum in kotlin.collections.Map<kotlin.String, ...> (MutableMap with modelMutable in the kotlin client), the same way lists are already handled. The new tests cover both generators. Fixes OpenAPITools#25453
Contributor
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java:1609">
P3: The new test only checks the immutable `kotlin.collections.Map` output. The `MutableMap` branch added to the data class templates for `modelMutable` is not exercised, so a regression there would go unnoticed. Add a case with `mutable=true` asserting `kotlin.collections.MutableMap<kotlin.String, Today.LessonStatus>`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| TestUtils.assertFileContains(modelKt, "val lessonStatus: kotlin.collections.Map<kotlin.String, Today.LessonStatus>"); | ||
| TestUtils.assertFileContains(modelKt, "val previousStatus: kotlin.collections.Map<kotlin.String, Today.PreviousStatus>? = null"); | ||
| TestUtils.assertFileContains(modelKt, "enum class LessonStatus(val value: kotlin.String)"); | ||
| TestUtils.assertFileContains(modelKt, "enum class PreviousStatus(val value: kotlin.String)"); |
Contributor
There was a problem hiding this comment.
P3: The new test only checks the immutable kotlin.collections.Map output. The MutableMap branch added to the data class templates for modelMutable is not exercised, so a regression there would go unnoticed. Add a case with mutable=true asserting kotlin.collections.MutableMap<kotlin.String, Today.LessonStatus>.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java, line 1609:
<comment>The new test only checks the immutable `kotlin.collections.Map` output. The `MutableMap` branch added to the data class templates for `modelMutable` is not exercised, so a regression there would go unnoticed. Add a case with `mutable=true` asserting `kotlin.collections.MutableMap<kotlin.String, Today.LessonStatus>`.</comment>
<file context>
@@ -1582,4 +1582,30 @@ public void testEnumUnknownDefaultCaseIsRegisteredAsCliOption() {
+ TestUtils.assertFileContains(modelKt, "val lessonStatus: kotlin.collections.Map<kotlin.String, Today.LessonStatus>");
+ TestUtils.assertFileContains(modelKt, "val previousStatus: kotlin.collections.Map<kotlin.String, Today.PreviousStatus>? = null");
+ TestUtils.assertFileContains(modelKt, "enum class LessonStatus(val value: kotlin.String)");
+ TestUtils.assertFileContains(modelKt, "enum class PreviousStatus(val value: kotlin.String)");
+ }
}
</file context>
This branch has not been deployed
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.
Description:
With the
kotlinandkotlin-springgenerators, an object property whoseadditionalPropertiesis an inline enum was typed as the nested enum (val lessonStatus: Today.LessonStatus) instead of a map of it. Such a property is flaggedisEnum, and the data class property templates only special-cased arrays, so theMapwas lost and decoding the JSON object failed.The property templates now wrap the nested enum in a map when
isMapis set, the same way lists of inline enums are already handled:kotlin-client/data_class_req_var.mustacheanddata_class_opt_var.mustache:kotlin.collections.Map<kotlin.String, Today.LessonStatus>(MutableMapwithmodelMutable)kotlin-spring/dataClassReqVar.mustacheanddataClassOptVar.mustache:Map<kotlin.String, Today.LessonStatus>Not addressed here: a map of lists or of maps of inline enums, the interface property templates, and nullable map values in
kotlin-spring.I added a test in
KotlinClientCodegenModelTestand one inKotlinSpringServerCodegenTestwith3_0/kotlin/issue25453-map-of-inline-enum.yaml. Both fail without the change.samples/has no diff.Fixes #25453
PR checklist
What I ran on this branch (macOS, JDK 21, Maven wrapper):
./mvnw -pl modules/openapi-generator -am test -Dtest=KotlinClientCodegenModelTest,KotlinClientCodegenApiTest,KotlinModelCodegenTest,KotlinSpringServerCodegenTestpasses (436 tests, 0 failures, 4 skipped). With the four templates put back to master, the two new tests fail../bin/generate-samples.shwith the 104kotlinandkotlin-springconfigs exits 0 and leavessamples/unchanged.jvm-retrofit2kotlinx client from the issue spec and built it with its Gradle wrapper. With this change it compiles, and a small local test (not committed) decodes{"lessonStatus":{"l1":"ready","l2":"failed"}}and readslessonStatus["l1"]. With master templates the same decode fails withJsonDecodingException ... at path: $.lessonStatus.kotlin-springserver from the issue spec and compiled it withmvn compileon its generatedpom.xml(its Gradle 8.1.1 wrapper does not run on JDK 21, with or without this change). The property isMap<String, Today.LessonStatus>with the change andToday.LessonStatuson master.I did not run the full
./mvnw clean package, the other sample configs or./bin/utils/export_docs_generators.sh, so the second box is unchecked. No option or docs text changed.cc @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l
Summary by cubic
Fixes the
kotlinandkotlin-springgenerators emitting object properties whoseadditionalPropertiesis an inline enum as the bare nested enum instead of aMap, which broke JSON decoding.Details
kotlin.collections.Map<kotlin.String, ...>(orMutableMapwithmodelMutablein thekotlinclient) when the property is an enum map, matching how lists of inline enums are handled.kotlin-spring.Fixes #25453.
Written for commit 5918977. Summary will update on new commits.