OpenAPITools / OpenAPITools/openapi-generator
[KOTLIN] Kotlin constructor for NotNull enum properties is not initialized correctly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
[KOTLIN] Constructor initialization for data Kotlin class and NotNull enum properties is not initialized correctly.
As result a build will fail with an error: "Classifier <> does not have a companion object, and thus must be initialized here".
openapi-generator version
openapi-generator-cli-4.1.2.jar
Steps to reproduce
package com.org.model
import java.util.Objects
@JsonIgnoreProperties(ignoreUnknown = true)
data class DocumentExchangeAdd (
@get:NotNull
@JsonProperty("DocumentType") var documentType: DocumentExchangeAdd.DocumentType
) {
constructor() : this(DocumentExchangeAdd.DocumentType)
enum class DocumentType(var value: kotlin.String) {
@JsonProperty("CreateNewSubmission") createNewSubmission("CreateNewSubmission"),
@JsonProperty("UpdateDocumentStatus") updateDocumentStatus("UpdateDocumentStatus"),
}
}
Suggest a fix
It has to be initialized by some default value, as on example below:
this(DocumentExchangeAdd.DocumentType.createNewSubmission)
However, I am not sure how to decided what is a default value.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Kotlin data class constructor shown in the reproduction and trace the Kotlin model generation path in openapi-generator 4.1.2. Check how NotNull enum properties receive no-argument defaults; done means generated code compiles without the companion-object error and uses a justified default enum value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100