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] OneOf base class not generated #9981

Open
5 of 6 tasks
rgranadosd opened this issue Jul 20, 2021 · 0 comments · May be fixed by #10009
Open
5 of 6 tasks

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

rgranadosd opened this issue Jul 20, 2021 · 0 comments · May be fixed by #10009

Comments

@rgranadosd
Copy link

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.

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