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

Problem generating Enum fields and pre/suffix #131

Closed
xtroce opened this issue Apr 30, 2020 · 2 comments · Fixed by #132
Closed

Problem generating Enum fields and pre/suffix #131

xtroce opened this issue Apr 30, 2020 · 2 comments · Fixed by #132
Assignees
Labels
bug Something isn't working
Milestone

Comments

@xtroce
Copy link

xtroce commented Apr 30, 2020

Hi,
We are trying to generate the code of the Shopify API from an introspection schema.
Waht we come across is the problem that when generating the code, if an enum is directly used in a field, the pre and suffix are ignored during this generation:

the following definintions in the schema lead to the following code which fails to compile since the class cannot be found. Leaving out the pre/suffix is no option since there is a class named Collection which will clash with the java one, since the includes use java.util.* and you will get ambiguity.

What you can see in the examples below is that the row

httpMethod: StagedUploadHttpMethodType = PUT

generates the following field in the class, where the suffix Graphql is missing

private StagedUploadHttpMethodTypeGraphql httpMethod = StagedUploadHttpMethodType.PUT;

the specific fields that show the problem and the generated code:

"""Possible HTTP method of a staged upload target."""
enum StagedUploadHttpMethodType {
  """The POST HTTP method."""
  POST

  """The PUT HTTP method."""
  PUT
}

"""
Specifies the fields required to generate the URL and parameters needed to upload an asset to Shopify.
"""
input StagedUploadTargetGenerateInput {
  """The resource type being uploaded."""
  resource: StagedUploadTargetGenerateUploadResource!

  """The filename of the asset being uploaded."""
  filename: String!

  """The MIME type of the asset being uploaded."""
  mimeType: String!

  """The HTTP method to be used by the staged upload."""
  httpMethod: StagedUploadHttpMethodType = PUT
}

which leads to the following generated code:

package nl.minc.shopify.graphql.model.client;

import java.util.*;

public class StagedUploadTargetGenerateInputGraphql {

    @javax.validation.constraints.NotNull
    private StagedUploadTargetGenerateUploadResourceGraphql resource;
    @javax.validation.constraints.NotNull
    private String filename;
    @javax.validation.constraints.NotNull
    private String mimeType;
    private StagedUploadHttpMethodTypeGraphql httpMethod = StagedUploadHttpMethodType.PUT;

    public StagedUploadTargetGenerateInputGraphql() {
    }

    public StagedUploadTargetGenerateInputGraphql(StagedUploadTargetGenerateUploadResourceGraphql resource, String filename, String mimeType, StagedUploadHttpMethodTypeGraphql httpMethod) {
        this.resource = resource;
        this.filename = filename;
        this.mimeType = mimeType;
        this.httpMethod = httpMethod;
    }

    public StagedUploadTargetGenerateUploadResourceGraphql getResource() {
        return resource;
    }
    public void setResource(StagedUploadTargetGenerateUploadResourceGraphql resource) {
        this.resource = resource;
    }

    public String getFilename() {
        return filename;
    }
    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getMimeType() {
        return mimeType;
    }
    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public StagedUploadHttpMethodTypeGraphql getHttpMethod() {
        return httpMethod;
    }
    public void setHttpMethod(StagedUploadHttpMethodTypeGraphql httpMethod) {
        this.httpMethod = httpMethod;
    }


    @Override
    public String toString() {
        StringJoiner joiner = new StringJoiner(", ", "{ ", " }");
        if (resource != null) {
            joiner.add("resource: " + resource);
        }
        if (filename != null) {
            joiner.add("filename: \"" + com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer.escapeJsonString(filename) + "\"");
        }
        if (mimeType != null) {
            joiner.add("mimeType: \"" + com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer.escapeJsonString(mimeType) + "\"");
        }
        if (httpMethod != null) {
            joiner.add("httpMethod: " + httpMethod);
        }
        return joiner.toString();
    }

    public static class Builder {

        private StagedUploadTargetGenerateUploadResourceGraphql resource;
        private String filename;
        private String mimeType;
        private StagedUploadHttpMethodTypeGraphql httpMethod = StagedUploadHttpMethodType.PUT;

        public Builder() {
        }

        public Builder setResource(StagedUploadTargetGenerateUploadResourceGraphql resource) {
            this.resource = resource;
            return this;
        }

        public Builder setFilename(String filename) {
            this.filename = filename;
            return this;
        }

        public Builder setMimeType(String mimeType) {
            this.mimeType = mimeType;
            return this;
        }

        public Builder setHttpMethod(StagedUploadHttpMethodTypeGraphql httpMethod) {
            this.httpMethod = httpMethod;
            return this;
        }


        public StagedUploadTargetGenerateInputGraphql build() {
            return new StagedUploadTargetGenerateInputGraphql(resource, filename, mimeType, httpMethod);
        }

    }
}

@kobylynskyi
Copy link
Owner

kobylynskyi commented Apr 30, 2020

@xtroce thanks for reporting this.
I will fix it asap.

By the way, which version of the plugin are you using?
Generic import import java.util.*` was replaced with fully-qualified imports in version 1.7.0.

Anyway, I will release the fix for enum default value generation in 1.7.2 today/tomorrow.

@kobylynskyi
Copy link
Owner

@xtroce the fix was released in version 1.7.2
Please allow several hours for maven central to reindex.

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