Customizations for @JsonTypeInfo and @JsonSubTypes in generated interfaces

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

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

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

評価

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

調査の方向性

まず、issue にあるスキーマとアノテーションの例を使って、generator がどのように interface を生成し、JsonTypeInfo および JsonSubTypes アノテーションを適用するかを追跡します。次に、カスタマイズによって __typename の代わりに既存のプロパティと enum 名を選択できる方法を特定し、その後、Animal、Dog、Cat の例で生成された出力を確認します。

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

説明

First of all, I really like your new GraphQL framework and this code generation plugin! It makes lots of stuff easier. I tried a few things and ran into a limitation using this code generator.

For example a schema looks like this:

interface Animal {
    name: String
    animalType: AnimalType
}

type Dog implements Animal {
    name: String
    animalType: AnimalType
    color: String
}

type Cat implements Animal {
    name: String
    animalType: AnimalType!
    eat: String
}

enum AnimalType {
    DOG
    CAT
}

The resulting interface for Animal has the following JsonTypeInfo:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "__typename"
)
@JsonSubTypes({
    @JsonSubTypes.Type(value = Dog.class, name = "Dog"),
    @JsonSubTypes.Type(value = Cat.class, name = "Cat")
})

The problem with this is, that I would like use a custom @JsonSubTypes configuration, using an existing property mapped to an enum value. It should look something like this:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.EXISTING_PROPERTY,
    property = "animalType",
    visible = true)
@JsonSubTypes({
    @JsonSubTypes.Type(value = Dog.class, name = "DOG"),
    @JsonSubTypes.Type(value = Cat.class, name = "CAT")
})

I realize that this is probably a complex issue, but I would like to know if something like this is even possible or a too specific problem?

With this the generator could be used to create a GraphQL schema for an existing service or database and create an lightweight GraphQL service ontop.

主要言語
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 を短くまとめたダイジェスト。