Bug Report Checklist
Description
During migration from java to kotlin Open API generator we encountered some issues with Map<String, Any?> data type. Our use case is:
- Application A has a data class with a
val dynamicProperties: Map<String, Any?> field in the API model
- We use sprindocs openapi-gradle-plugin gradle plugin in version 1.7.0 to generate openApi.yml specification
- We use org.openapi.generator gradle plugin in version 7.0.0 with configuration described in Generation Details to generate SDKs for API
- Data class mentioned in point 1 has a
val dynamicProperties: Map<String, Any> field in generated code.
Nullability of the values in this map is important for us and we don't want to change it.
Would it be possible to support nullable value types in kotlin maps?
openapi-generator version
7.0.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: OpenAPI Petstore
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
paths:
/nullableMapValue:
get:
responses:
'200':
description: 'nullable map value'
content:
application/json:
schema:
$ref: '#/components/schemas/ExampleClass'
components:
schemas:
ExampleClass:
required:
- dynamicProperties
type: object
properties:
dynamicProperties:
type: object
additionalProperties:
type: object
Generation Details
Gradle org.openapi.generator plugin in version 7.0.0 was used with following configuration:
openApiGenerate {
val packageName = "org.example"
generatorName.set("kotlin")
library.set("jvm-spring-webclient")
inputSpec.set(tasks.generateOpenApiDocs.flatMap { it.outputFile })
outputDir.set("$buildDir/generated/open-api-client")
this.packageName.set(packageName)
apiPackage.set("$packageName.api")
modelPackage.set("$packageName.model")
configOptions.set(
mapOf(
"serializationLibrary" to "jackson",
"dateLibrary" to "java8",
"useSpringBoot3" to "false",
"enumPropertyNaming" to "UPPERCASE"
)
)
importMappings.set(
mapOf(
"Pageable" to "org.springframework.data.domain.Pageable"
)
)
}
Steps to reproduce
It is reproducable by adding this test case to KotlinModelCodegenTest.java while having attached yaml added to test resources:
@Test(dataProvider = "generators")
public void mapWithNullableValues(AbstractKotlinCodegen codegen) throws IOException {
String outputPath = generateModels(codegen, "src/test/resources/3_0/maps-with-nullable-values.yaml", false);
assertFileContains(
Paths.get(outputPath + "/src/main/kotlin/models/ExampleClass.kt"),
"val dynamicProperties: kotlin.collections.Map<kotlin.String, kotlin.Any>"
);
}
Related issues/PRs
No related issues found.
Bug Report Checklist
Description
During migration from
javatokotlinOpen API generator we encountered some issues withMap<String, Any?>data type. Our use case is:val dynamicProperties: Map<String, Any?>field in the API modelval dynamicProperties: Map<String, Any>field in generated code.Nullability of the values in this map is important for us and we don't want to change it.
Would it be possible to support nullable value types in kotlin maps?
openapi-generator version
7.0.0
OpenAPI declaration file content or url
Generation Details
Gradle org.openapi.generator plugin in version 7.0.0 was used with following configuration:
Steps to reproduce
It is reproducable by adding this test case to
KotlinModelCodegenTest.javawhile having attachedyamladded to test resources:Related issues/PRs
No related issues found.