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

vcloud openapi v37.2 Java generation #14

Open
tvs61 opened this issue Jun 29, 2023 · 5 comments
Open

vcloud openapi v37.2 Java generation #14

tvs61 opened this issue Jun 29, 2023 · 5 comments

Comments

@tvs61
Copy link

tvs61 commented Jun 29, 2023

I'm attempting to use the 37.2.json spec to generate java objects via openapi-generator-cli-6.6.0 running under JDK11 and the resulting maven project won't build due to errors related to the "type" variable derived from the spec. I was seeing this same issue when using the 37.0 spec as well.

In short, it appears that "type" and "_type" in the generated VcloudQueryResultRecordType class conflict. Specifically:

  public static final String SERIALIZED_NAME_TYPE = "type";
  @SerializedName(SERIALIZED_NAME_TYPE) private String type;

  public static final String SERIALIZED_NAME_TYPE = "_type";
  @SerializedName(SERIALIZED_NAME_TYPE) protected String type;

Which results in these 3 methods being duplicated in VcloudQueryResultRecordType (once for "type" and once for "_type"):

  public VcloudQueryResultRecordType type(String type) {

    this.type = type;
    return this;
  }

  /**
   * Contains the type of the resource.
   * @return type
   **/
  @javax.annotation.Nullable
  public String getType() {
    return type;
  }

  public void setType(String type) { this.type = type; }

  public VcloudQueryResultRecordType link(List<VcloudLinkType> link) {

    this.link = link;
    return this;

This in-turn throws off any other generated VcloudQueryResult* classes which descend from VcloudQueryResultRecordType.

From what I can tell, the "_type" discriminator is the root of my problems (from the spec):

      "vcloud_QueryResultRecordType": {
        "title": "vcloud_QueryResultRecordType",
        "description": "Base type for a single record from query result in records format. Subtypes define more specific elements.",
        "discriminator": {
          "propertyName": "_type",

Is there a particular option I need to provide to openapi-generator-cli-6.6.0 to generate better/compiling Java? I've attempted with various combinations of discriminatorCaseSensitive, legacyDiscriminatorBehavior, x-discriminator-value, etc - but none of those appear to make any difference in the generated output. Perhaps I'm looking in the wrong place WRT the discriminator value?

Thanks in advance.

@tvs61
Copy link
Author

tvs61 commented Jun 29, 2023

Nevermind - duplicate of #3 Not sure how I missed that.

@tvs61 tvs61 closed this as completed Jun 29, 2023
@tvs61 tvs61 reopened this Jun 29, 2023
@tvs61
Copy link
Author

tvs61 commented Jun 29, 2023

Perhaps I'm being dense, but after applying the patch the resulting generated code still won't compile, albeit with slightly different behavior.

In VcloudQueryResultRecordType both of these remain:

  public static final String SERIALIZED_NAME_TYPE = "type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  private String type;

  public static final String SERIALIZED_NAME_TYPE = "_type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  protected String type;

and various other classes are complaining that "_type cannot be resolved to a variable" as well as duplicate field/method complaints.

@mzvankovich
Copy link
Collaborator

mzvankovich commented Jun 29, 2023

Perhaps I'm being dense, but after applying the patch the resulting generated code still won't compile, albeit with slightly different behavior.

In VcloudQueryResultRecordType both of these remain:

  public static final String SERIALIZED_NAME_TYPE = "type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  private String type;

  public static final String SERIALIZED_NAME_TYPE = "_type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  protected String type;

and various other classes are complaining that "_type cannot be resolved to a variable" as well as duplicate field/method complaints.

Hello, I've just checked the patch script. That one is not relevant any more, I'll provide working one as soon as possible. Please bear in mind that it is still a temporary solution until openapi codegen is fixed.

@tvs61
Copy link
Author

tvs61 commented Jun 29, 2023

Thanks in advance. Understood, that it's just temporary and I appreciate the patch.

@mzvankovich
Copy link
Collaborator

Thanks in advance. Understood, that it's just temporary and I appreciate the patch.

I've updated patch scripts and README accordinly, see for details: Known Issues . The patch works for a java codegenerated client only. Let me know if there are issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants