Skip to content

[BUG] [Spring] OneOf base class not generated #9981

@rgranadosd

Description

@rgranadosd

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

While generating a Java server code with polymorphism (oneOf), we get a compilation error while the base class is imported due to it was not generated.

openapi-generator version

5.2.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: OneOf example
  version: '1.0.0'
paths:
  '/vegetables':
    get:
      summary: Get vegetables
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                oneOf:
                - $ref: '#/components/schemas/Tomato'
                - $ref: '#/components/schemas/Carrot'
        '404':
          description: Not Found
      operationId: getVegetables
components:
  schemas:
    Tomato:
      type: object
      properties:
        property1:
          type: integer
        property2:
          type: string
    Carrot:
      type: object
      properties:
        property3:
          type: integer
        property4:
          type: string  

Plugin configuration:

<plugin>
	<version>5.2.0</version>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-rest-api</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/openapi-rest.yml</inputSpec>
                <generatorName>spring</generatorName>
                <generateSupportingFiles>true</generateSupportingFiles>                
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                    <java8>true</java8>
                    <interfaceOnly>true</interfaceOnly>
                    <apiPackage>com.example</apiPackage>                    
                    <modelPackage>com.example.dto</modelPackage>
                    <sourceFolder>src/gen/java/main</sourceFolder>                    
                </configOptions>
            </configuration>
        </execution>       
    </executions>    
</plugin>
Generation Details
Steps to reproduce

Generate code with openapi-generator-maven-plugin.

  • Add the openapi-generator-maven-plugin to a pom.xml
  • Add the previous OpenAPI to a file named openapi-rest.yml at ${project.basedir}/src/main/resources/
  • Execute mvn clean compile
  • Check the compilation error at DefaultApi.java file. It's trying to import a OneOfTomatoCarrot, but it has not been generated.
Related issues/PRs
Suggest a fix

Following the provided example, a OneOfTomatoCarrot class must be generated.

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