Unable to generate constructor param and populate companion object in models and enum
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 217
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to generate an enum class with a label as the constructor param and have a function in the companion object.
The schema GraphQL looks like
type Account {
accountId: String!
accountNumber: Int!
accountStatus: AccountStatus
accountBalance: Float!
}
enum AccountStatus {
ACTIVE,
INACTIVE,
CLOSED,
UNKNOWN
}
and the generated enum looks like
@Generated(
value = ["com.netflix.graphql.dgs.codegen.CodeGen"],
date = "2022-08-09T22:03:45.581297Z",
)
public enum class AccountStatus {
ACTIVE,
INACTIVE,
CLOSED,
UNKNOWN,
;
public companion object
}
My goal is to have the following enum class generated
enum class AccountStatus(val label: String) {
UNKNOWN("UNKNOWN"),
ACTIVE("ACTIVE"),
INACTIVE("INACTIVE"),
LOCKED("LOCKED");
companion object {
fun fromLabelString(label: String?): AccountStatus {
return if (label == null) {
UNKNOWN
} else {
values().find { it.label.equals(label) } ?: UNKNOWN
}
}
}
}
I was unable to find documentation regarding generating custom enums and classes and wanted to know if this is currently possible and if not what would be the recommended way to achieve this?
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
The issue names no source files or tests. Start by reviewing the Kotlin enum and model generation options, then compare supported configuration with the requested constructor parameter and companion-object function. Done means establishing whether this behavior is supported and documenting or scoping the required change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend-api-design, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100