OpenAPITools / OpenAPITools/openapi-generator

jaxrs-spec generator could not handle enumerations defined with anyOf

Open
#19,639 1 comment 0 reactions 1 assignee View on GitHub

@kay-schecker is already working on this.

Since Apr 8, 2023.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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;
....
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.