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

[jaxrs-resteasy/anyOf] code generator doesn't generate good java classes for types based on anyOf #559

Open
tnmtechnologies opened this issue Jul 13, 2018 · 5 comments

Comments

@tnmtechnologies
Copy link
Contributor

Description

When a declared type is based on an anyOf, the generated java class owns no attribute, just default methods from Object class.
It leads to an error at runtime because the json value can't be bound to its bean class by jaxrs framework.

anyOf declaration seems to not be supported by code generator while it is part of OpenApi 3 standard.

openapi-generator version

openapi-generator-cli-3.1.0.jar

OpenAPI declaration file content or url

The file TS29571_CommonData.yaml contains this declared defintion RatType

     RatType:
       anyOf:
       - type: string
         enum:
           - NR
           - EUTRA
           - WLAN
           - VIRTUAL
       - type: string

which is used in file TS29518_Namf_MT.yaml

Command line used for generation

We suppose the file openapi-generator-cli-3.1.0.jar is in the current folder
and yaml files in a folder named yaml

rm -fr target/samples.openapi && java -jar ./openapi-generator-cli-3.1.0.jar generate -i yaml/TS29518_Namf_MT.yaml -g jaxrs-resteasy -o target/samples.openapi

Steps to reproduce

The issue has been found at runtime. It means we should need to build a war or jar file and put in its given runtime environment. These steps will take time.
A quickest solution to look to the issue is to open the generated class file RatType.java which looks like this:

package org.openapitools.model;

import java.util.Objects;
import java.util.ArrayList;
import javax.validation.constraints.*;
import io.swagger.annotations.*;


@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaResteasyServerCodegen", date = "2018-07-13T15:42:47.770312700+02:00[Europe/Paris]")
public class RatType   {
  


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    RatType ratType = (RatType) o;
    return true;
  }

  @Override
  public int hashCode() {
    return Objects.hash();
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class RatType {\n");
    
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }
}

As we can see there is no attribute in this generated class. Some pieces of code miss.

Related issues/PRs
Suggest a fix/enhancement

The fix should generates the source code related to the attributes defined in the OpenApi file.
yaml.zip

@mudged
Copy link

mudged commented Jan 22, 2019

Hi,

Is there any update on this issue?

Also, I think it may be a duplicate / related to #798

Thanks

@dskvr
Copy link

dskvr commented Feb 8, 2019

This is a common problem in all swagger generators. Basically, if you're using OAS, design your API to provide consistent responses.

@jphorx
Copy link

jphorx commented Apr 9, 2019

This is a common problem in all swagger generators. Basically, if you're using OAS, design your API to provide consistent responses.

Unfortunately this is not always possible. In this case, the API is defined by the 3GPP standards body as part of the 5G core standards.

@maxl2287
Copy link

Same problem still in the year 2023.
Like @jphorx I am also using 3GPP standards, where I cannot update the Specification-YAML.
But I face the same issue when having "anyOf" like that example in the issue.

Retested with v7.1.0

@wing328 please help us here

@maxl2287
Copy link

Okay it is working for my use-case with:

              <openapiNormalizer>
                SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true
              </openapiNormalizer>

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

5 participants