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-spec generator could not handle enumerations defined with anyOf #702

Open
omerdogan opened this issue Apr 8, 2023 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@omerdogan
Copy link

omerdogan commented Apr 8, 2023

openapi generate could not handle enumerations defined with anyOf, it will generate an empty enumeration class, i think the correct behavior is generating enumeration class with the values defined in yaml schema and Referencing class properties are defined as String

openapi-generator-cli-6.5.0.jar dont generate any AnyOf classes,
openapi-generator-cli-6.4.0.jar generate AnyOf classes if "--global-property models" flag is not provided
both versions generate an empty NEvent enumeration class

Assume that the following schema part is given ,
openapi-generator-cli-6.4.0 generate NEvent.java and NEventAnyOf.java , but if --global-property-models is given as below, it will only generate Nevent.java
openapi-generator-cli-6.5.0 never generate AnyOf classes

schema:
   Event:
     anyOf:
     - type: string
       enum:
         - SESSION_TERMINATION
         - LOSS_OF_BEARER 
         - RECOVERY_OF_BEARER
         - RELEASE_OF_BEARER
         - USAGE_REPORT
         - FAILED_RESOURCES_ALLOCATION
     - type: string

Sample command line ;
java -Dresolve=true -Dlog.level=info -Dmodels -Duser.language=en -Dfile.encoding=UTF-8 -Xmx256M -jar 'D:\home\omerd\n5g\codegen\openapi-generator-cli-6.4.0.jar'
generate --api-package mypackage
--model-package mymodelpackage
--invoker-package myinvokerpackage
--group-id mygroup
--artifact-id myartifact
--model-name-prefix N
--generator-name jaxrs-spec
--skip-validate-spec
--config config.yml
--input-spec target.yaml
--openapi-normalizer REF_AS_PARENT_IN_ALLOF=true
--import-mappings=Date=java.util.Date,DateTime=java.util.Date
--type-mappings=Date=Date,DateTime=DateTime
--global-property models=Event:EnumModel2:model3:model4
--output output

Generated Event Class:

@JsonTypeName("Event")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen")
public class NEvent   {
 @Override
 public boolean equals(Object o) {
   if (this == o) {
     return true;
   }
   if (o == null || getClass() != o.getClass()) {
     return false;
   }
   return true;
 }

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

 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("class NEvent {\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(Object o) {
   if (o == null) {
     return "null";
   }
   return o.toString().replace("\n", "\n    ");
 }
}

Generated AnyOf Class:

public enum NEventAnyOf {
 
 SESSION_TERMINATION("SESSION_TERMINATION"),
 
 LOSS_OF_BEARER("LOSS_OF_BEARER"),
 
 RECOVERY_OF_BEARER("RECOVERY_OF_BEARER"),
 
 RELEASE_OF_BEARER("RELEASE_OF_BEARER"),
 
 USAGE_REPORT("USAGE_REPORT"),
 
 FAILED_RESOURCES_ALLOCATION("FAILED_RESOURCES_ALLOCATION");

 private String value;
....
}
@omerdogan omerdogan added the bug Something isn't working label Apr 8, 2023
@omerdogan omerdogan changed the title jaxrs-spec generator dont generate AnyOf classes jaxrs-spec generator could not handle enumerations defined with anyOf Apr 8, 2023
@AienTech
Copy link

This is quite a serious one. I'm wondering how it has been fixed, or is it even fixed?

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

No branches or pull requests

3 participants