[BUG] [Kotlin-spring] Multiple errors in model default values
Created by: sigand
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating models with default values, I have come across multiple bugs. Arrays: default value is not respected Strings: Is generated with " instead of " (double quote), which makes it not compile Enums: Inline enums are generated with the wrong names, which makes it not compile. Note this one has a relatively easy workaround, define enums as separate schemas.
openapi-generator version
openapigenerator: 5.1.1 kotlin: 1.5.10 gradle: 7.1
OpenAPI declaration file content or url
Minimal schema
"Test": {
"title": "TestObject",
"type": "object",
"required": [ "testArray" ],
"properties": {
"stringDefault": {
"type": "string",
"default": "test"
},
"testArray": {
"type": "array",
"default": [],
"items": {
"type": "string"
}
},
"testArrayOptional": {
"type": "array",
"default": [],
"items": {
"type": "string"
}
},
"testEnum": {
"type": "string",
"enum": [ "A", "B", "C" ],
"default": "C"
}
}
}
Results
data class Test(
@field:JsonProperty("stringDefault", required = true) val stringDefault: kotlin.String = "test",
@field:JsonProperty("testArray", required = true) val testArray: kotlin.collections.List<kotlin.String>,
@field:JsonProperty("testArrayOptional") val testArrayOptional: kotlin.collections.List<kotlin.String>? = null,
@field:JsonProperty("testEnum") val testEnum: Test.TestEnum? = TestEnumEnum.c
) {
enum class TestEnum(val value: kotlin.String) { a("A"), b("B"), c("C") }
}
Generation Details
Using gradle
task generateExample(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
inputSpec = "$rootDir/test.json"
generatorName = "kotlin-spring"
outputDir = "$buildDir/generated/testing"
}
Related issues/PRs
Might be related to https://github.com/OpenAPITools/openapi-generator/pull/8373