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

[BUG] [SPRING] OpenAPI Generator generates enums with that does not implement the interface for model with "OneOf" in the schema #17347

Open
3 of 6 tasks
jimisola opened this issue Dec 8, 2023 · 0 comments

Comments

@jimisola
Copy link

jimisola commented Dec 8, 2023

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version

7.1.0

OpenAPI declaration file content or url
      "DefaultPublicationType": {
        "type": "string",
        "enum": [
          "FLIGHT_DATA",
          "ARRIVAL_SEQUENCE_DATA",
          "AIRPORT_CONFIGURATION_DATA"
        ]
      },
      "OtherPublicationType": {
        "type": "string",
        "pattern": "^OTHER:[A-Z_][A-Z0-9_]*$"
      },
      "Publication": {
        "description": "A SWIM Publication identifies a topic together with its content type, formal content type definition, and supported filters.",
        "oneOf": [
          {
            "$ref": "#/components/schemas/DefaultPublicationType"
          },
          {
            "$ref": "#/components/schemas/OtherPublicationType"
          }
        ]
      },
Generation Details
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public interface Publication {
}
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public enum DefaultPublicationType {
  
  FLIGHT_DATA("FLIGHT_DATA"),
  
  ARRIVAL_SEQUENCE_DATA("ARRIVAL_SEQUENCE_DATA"),
  
  AIRPORT_CONFIGURATION_DATA("AIRPORT_CONFIGURATION_DATA");

  private String value;

  DefaultPublicationType(String value) {
    this.value = value;
  }

  @JsonValue
  public String getValue() {
    return value;
  }

  @Override
  public String toString() {
    return String.valueOf(value);
  }

  @JsonCreator
  public static DefaultPublicationType fromValue(String value) {
    for (DefaultPublicationType b : DefaultPublicationType.values()) {
      if (b.value.equals(value)) {
        return b;
      }
    }
    throw new IllegalArgumentException("Unexpected value '" + value + "'");
  }
}
Steps to reproduce
 <configuration>
                            <!-- see: https://openapi-generator.tech/docs/generators/spring/-->
                            <skipValidateSpec>true</skipValidateSpec>
                            <inputSpec>${project.basedir}/src/main/resources/openapi.json</inputSpec>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <useSpringBoot3>true</useSpringBoot3>
                                <useOneOfInterfaces>true</useOneOfInterfaces>
                                <useOptional>true</useOptional>
                                <annotationLibrary>swagger2</annotationLibrary>
                                <delegatePattern>true</delegatePattern>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <hateoas>true</hateoas>
                                <useBeanValidation>true</useBeanValidation>
                                <performBeanValidation>true</performBeanValidation>
                            </configOptions>
                        </configuration>
Related issues/PRs

#16672 #14807 #11715 #15

Suggest a fix

The generated enumeration should implement the interface.

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

No branches or pull requests

1 participant