Skip to content

[BUG] [Spring] oneOf, anyOf support for List inside DTO #8022

@UNiqkue

Description

@UNiqkue

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

Spring openapi-generator-maven-plugin doesn't support oneOf.
изображение

openapi-generator version

4.3.1

pom.xml

 <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.3.1</version>
                <executions>
                    <execution>
                        <id>client</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>api.yml</inputSpec>
                            <output>codegen/client</output>
                            <generatorName>java</generatorName>
                            <configOptions>
                                <library>resttemplate</library>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <serializableModel>false</serializableModel>
                                <bigDecimalAsString>false</bigDecimalAsString>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                                <interfaceOnly>true</interfaceOnly>
                            </configOptions>
                            <generateApiTests>false</generateApiTests>
                            <generateModelTests>false</generateModelTests>
                        </configuration>
                    </execution>
                    <execution>
                        <id>server</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <inputSpec>api.yml</inputSpec>
                            <output>codegen/server</output>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <serializableModel>false</serializableModel>
                                <bigDecimalAsString>false</bigDecimalAsString>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                                <interfaceOnly>true</interfaceOnly>
                                <useBeanValidation>true</useBeanValidation>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
OpenAPI declaration file content or url

I tried to generate:

api.yml

openapi: "3.0.0"
info:
  version: "1.0"
  title: "Main"

paths:
  /class:
    get:
      responses:
        200:
          description: Ok
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MainClass"

components:
  schemas:
    MainClass:
      type: object
      properties:
        fieldName:
          type: array
          items:
            oneOf:
              - $ref: "#/components/schemas/ObjectA"
              - $ref: "#/components/schemas/ObjectB"

    ObjectA:
      type: object
      properties:
        name:
          type: string
    ObjectB:
      type: object
      properties:
        name:
          type: string
Generation Details

When I use

...
<generatorName>java</generatorName>
   <configOptions>
        <library>resttemplate</library>
...

I get MainClass

...
public class MainClass {
  public static final String JSON_PROPERTY_FIELD_NAME = "fieldName";
  private List<MainClassFieldNameOneOf> fieldName = null;
...

which contains list of interfaces MainClassFieldNameOneOf. And ObjectA and ObjectB implement this interface.
Things are good.

BUT need SPRING and when use

...
<generatorName>spring</generatorName>
...

the interface OneOfObjectAObjectB is not generated

Steps to reproduce
  • create a pom.xml with openapi-generator-maven-plugin 4.3.1
  • create api.yml file above
  • mvn clean generate-sources
  • see broken code under target directory codegen\server\src\main\java\org\openapitools\model -> MainClass
Related issues/PRs
Suggest a fix

This bug is related to the Server side Java code (SpringBoot)
#2906

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions