Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9981
Closed
Open
Issue created Jul 20, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [Spring] OneOf base class not generated

Created by: 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
  • https://github.com/OpenAPITools/openapi-generator/pull/5661
  • https://github.com/OpenAPITools/openapi-generator/issues/5381
Suggest a fix

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

Assignee
Assign to
Time tracking