Netflix / Netflix/dgs-codegen

support Implementing interfaces with covariant return types

Open
#92 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

This is to support implementing an interface by allowing an implementing field to return a subtype of the interface field's return type.

interface Friendly {
  bestFriend: Friendly
}

type Person implements Friendly {
  bestFriend: Person
}

// Generated java interface 
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "__typename"
)
@JsonSubTypes(@JsonSubTypes.Type(value = Person.class, name = "Person"))
public interface Friendly {
  Friendly getBestFriend();

  void setBestFriend(Friendly bestFriend);
}

// generated java class
public class Person implements Friendly {
  private Person bestFriend;

  public Person getBestFriend() {
    return bestFriend;
  }

  public void setBestFriend(Person bestFriend) {
    this.bestFriend = bestFriend;
  }

The generated java code doesn't compile, as the class needs to implement the setter with "interface" parameter definition like that:

public void setBestFriend(Friendly bestFriend) {
    this.bestFriend = bestFriend;
  }

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 by locating the Java interface and implementing-class generation logic for fields such as bestFriend, then inspect the related generator tests if present. Done means the generated Person class compiles while implementing Friendly, including compatible getter and setter signatures for the subtype return and interface parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.