OpenAPITools / OpenAPITools/openapi-generator

[KOTLIN] Kotlin constructor for NotNull enum properties is not initialized correctly

Open
#4,644 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.