OpenAPITools / OpenAPITools/openapi-generator
[REQ][KOTLIN] Empty companion object on every generated class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Please create an (empty) companion object for every generated class. It enables users to define extension functions on the companion.
This is useful because it allows users to add factory functions or constructor like functions to a type.
Describe the solution you'd like
Every generated (data) class should have a companion object. If it does not need to have methods it shall be empty.
Example:
definition:
components:
schemas:
CheckResult:
description: Holds a check result.
type: object
required:
- checkType
properties:
checkType:
type: string
description: The type of the check
generated code before:
/**
* Holds a check result.
* @param checkType The type of the check
*/
data class CheckResult(
@field:JsonProperty("checkType", required = true) val checkType: kotlin.String,
)
generated code with the feature implemented:
/**
* Holds a check result.
* @param checkType The type of the check
*/
data class CheckResult(
@field:JsonProperty("checkType", required = true) val checkType: kotlin.String,
){
companion object
}
Describe alternatives you've considered
Without an existing companion object we cannot define extension functions on a type. The alternative is to use factory methods which are not discoverable just from the type, which is not the best editing experience.
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 by tracing the Kotlin model-generation path that produces the CheckResult example. Verify generated output for a data class with no existing companion object; the work is done when every generated class includes an empty companion object and the generated Kotlin remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100