Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9844
Closed
Open
Issue created Jun 25, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

Assignee
Assign to
Time tracking