Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation is broken with comments on interfaces' fields (Version: 1.7.0) #128

Closed
Lukas-Kullmann opened this issue Apr 28, 2020 · 1 comment · Fixed by #129
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Lukas-Kullmann
Copy link

Lukas-Kullmann commented Apr 28, 2020

Issue Description

In version 1.7, generating code for this example (based on example No 62 from the spec), will result in an error:

interface NamedEntity {
  # an awesome name!
  name: String
}

type Person implements NamedEntity {
  name: String

  # age in years
  age: Int
}

Expected Result

The code is generated correctly

Actual Result

An error occurrs during compilation:

Error:(8,20) java: variable name is already defined in class com.example.Person
Error:(13,52) java: variable name is already defined in constructor Person(java.lang.String,java.lang.Integer,java.lang.String)
Error:(42,19) java: method getName() is already defined in class com.example.Person
Error:(48,17) java: method setName(java.lang.String) is already defined in class com.example.Person
Error:(58,24) java: variable name is already defined in class com.example.Person.Builder
Error:(79,24) java: method setName(java.lang.String) is already defined in class com.example.Person.Builder

The generated code is:

NamedEntity.java

package com.example.api;


public interface NamedEntity {

    /**
     * an awesome name!
     */
    String getName();

}

Person.java
Note that name is generated twice because of the comment in the interface.
If I remove the comment in the interface, it works fine.

package com.example.api;


public class Person implements NamedEntity{

    private String name;
    private Integer age;
    private String name;

    public Person() {
    }

    public Person(String name, Integer age, String name) {
        this.name = name;
        this.age = age;
        this.name = name;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    /**
     * age in years
     */
    public Integer getAge() {
        return age;
    }
    /**
     * age in years
     */
    public void setAge(Integer age) {
        this.age = age;
    }

    /**
     * an awesome name!
     */
    public String getName() {
        return name;
    }
    /**
     * an awesome name!
     */
    public void setName(String name) {
        this.name = name;
    }



    public static class Builder {

        private String name;
        private Integer age;
        private String name;

        public Builder() {
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        /**
         * age in years
         */
        public Builder setAge(Integer age) {
            this.age = age;
            return this;
        }

        /**
         * an awesome name!
         */
        public Builder setName(String name) {
            this.name = name;
            return this;
        }


        public Person build() {
            return new Person(name, age, name);
        }

    }
}

Your Environment and Setup

  • graphql-java-codegen: 1.7.0
  • Build tool: Maven
  • Java tool: openjdk 11.0.6 2020-01-14
  • Mapping Config: It won't tell you much. It's just the paths config
<configuration>
  <graphqlSchemaPaths>
    <graphqlSchemaPath>${graphql.schema.path}</graphqlSchemaPath>
  </graphqlSchemaPaths>
  <outputDir>${graphql-codegen-maven-plugin.outputDir}</outputDir>
  <packageName>${server.packageName}</packageName>
</configuration>

Additional context

It works with 1.6.0

@Lukas-Kullmann Lukas-Kullmann added the bug Something isn't working label Apr 28, 2020
@kobylynskyi
Copy link
Owner

kobylynskyi commented Apr 28, 2020

Thank you @Lukas-Kullmann
I will fix it today as part of 1.7.1
It should be released on Wednesday.

@kobylynskyi kobylynskyi self-assigned this Apr 28, 2020
@kobylynskyi kobylynskyi added this to the 1.7.1 milestone Apr 28, 2020
kobylynskyi added a commit that referenced this issue Apr 29, 2020
* Handle duplicate fields from the type and interface #128

* Take annotations and javadoc from the type and not the interface #128

* Refactor and add some unit tests

* Simplify the code in TypeDefinitionToDataModelMapper #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants