Netflix / Netflix/dgs-codegen

Enum imports when using includeEnumImports do not generate a static import statement in the generated types file.

Open
#595 1 comment 1 reaction 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

The custom annotation follows the below schema:

type Person @annotate(name: "ValidPerson", type: "validator", inputs: {types: [HUSBAND, WIFE]}) {
       name: String
}

This is expected to generate a Java class looking like the below:

package com.netflix.graphql.dgs.codegen.tests.generated.types;

import com.test.validator.ValidPerson;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;

@ValidPerson(
    types = [com.enums.PersonType.HUSBAND, com.enums.PersonType.WIFE]
)
public class Person {
  private String name;
  // Ignoring other boilerplate code because it is irrelevant to this example. 
}

Note that in the build.gradle file, the following has been added:

generateJava {
    //...
    generateCustomAnnotations = true,
    includeImports = mapOf(Pair("validator", "com.test.validator")),
    includeEnumImports = ["ValidPerson": ["types": "com.enums.PersonType"]]
}

However, the generated class looks like the below instead:

package com.netflix.graphql.dgs.codegen.tests.generated.types;

import com.enums.PersonType.HUSBAND;
import com.enums.PersonType.WIFE;
import com.test.validator.ValidPerson;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;

@ValidPerson(
    types = [HUSBAND, WIFE]
)
public class Person {
  private String name;
  // Ignoring other boilerplate code because it is irrelevant to this example. 
}

Since Java expects all enum imports to be static, the above-generated code causes a compile time error.

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 tracing the includeEnumImports configuration from build.gradle into the generator that writes the generated types file. Compare the expected static imports with the current enum-member imports; done means the generated annotation uses static imports and the resulting Java compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
build-system, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.