[kotlin][kotlin-spring] Keep the Map type for properties whose additionalProperties is an inline enum
Description:
With the kotlin and kotlin-spring generators, an object property whose additionalProperties is an inline enum was typed as the nested enum (val lessonStatus: Today.LessonStatus) instead of a map of it. Such a property is flagged isEnum, and the data class property templates only special-cased arrays, so the Map was lost and decoding the JSON object failed.
The property templates now wrap the nested enum in a map when isMap is 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 KotlinClientCodegenModelTest and one in KotlinSpringServerCodegenTest with 3_0/kotlin/issue25453-map-of-inline-enum.yaml. Both fail without the change. samples/ has no diff.
Fixes #25453
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples (see below for what I ran instead):
./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
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.- I generated a
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. - I generated the
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 kotlin and kotlin-spring generators emitting object properties whose additionalProperties is an inline enum as the bare nested enum instead of a Map, which broke JSON decoding.
Details
- Data class property templates now emit
kotlin.collections.Map<kotlin.String, ...>(orMutableMapwithmodelMutablein thekotlinclient) when the property is an enum map, matching how lists of inline enums are handled. - Adds tests in both generators covering required, optional, and nullable map-of-inline-enum properties.
- Not addressed: maps of lists or maps of inline enums, interface property templates, and nullable map values in
kotlin-spring.
Fixes #25453.