Unable to generate constructor param and populate companion object in models and enum

オープン
#441 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
kotlin

調査の方向性

この issue ではソースファイルもテストも指定されていません。まず Kotlin の enum とモデル生成オプションを確認し、次に、サポートされている設定と、要求されているコンストラクターパラメーターおよび companion object の関数を比較してください。完了条件は、この動作がサポートされているかどうかを明確にし、必要な変更を文書化するか、範囲を定めることです。

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
Kotlin
スター
220
フォーク
123
平均マージ
1日 6時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Netflix/dgs-codegen のほかの issue

Netflix/dgs-codegen の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。