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
  • #11715
Closed
Open
Issue created Feb 25, 2022 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG] Java generator does not generate oneOf interface

Created by: Daemorinumi

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

the java generator on openapi-generator-maven-plugin 5.4.0 doesn't compile with an openapi which contain an oneOf instructions. The interfaces OneOf are not generated.

Compilation failure: Compilation failure:
[ERROR] /Users/XXX/git/service/contract/target/generated-sources/openapi/src/main/java/blabla/model/Person.java:[48,23] error: cannot find symbol
[ERROR]   symbol:   class OneOfCatDog
[ERROR]   location: class Person

I tried with previous versions and the only one which compile is the 4.3.1. Unfortunately the generated interface contain an empty JsonSubTypes annotation : the mapper cannot map correctly the object

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-02-25T12:39:36.701392+01:00[Europe/Paris]")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "pet_type", visible = true)
@JsonSubTypes({
})

public interface PersonPetOneOf  {
    public String getPetType();
}
openapi-generator version

version : 5.4.0

OpenAPI declaration file content or url
openapi: "3.0.3"
info:
  title: "notification"
  version: "1.0"
tags:
  - name: notify
servers:
  - url: /person
paths:
  /person:
    post:
      security:
        - basicAuth: []  
      tags:
        - notify
      operationId: aaa
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Person'
      responses:
        '200':
          description : "retour ok"
         
components:
  securitySchemes:
    basicAuth:    
      type: http
      scheme: basic
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    Dog:    
      allOf:  
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:     
      allOf: 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer
    Person:
      properties:
        name:
          type : string
        pet:
          oneOf:
             - $ref: '#/components/schemas/Cat'
             - $ref: '#/components/schemas/Dog'
          discriminator:
            propertyName: pet_type
Generation Details

java : version 11 maven : version 3.5.3 pom.xml

<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>5.4.0</version>
	<!-- <version>4.3.1</version> -->
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>${project.basedir}/src/main/resources/static/openapi/notifier-v1.yaml</inputSpec>
				<generatorName>java</generatorName>
				<apiPackage>blabla.api</apiPackage>
				<modelPackage>blabla.model</modelPackage>
				<library>resttemplate</library>
				<configOptions>
					<generateModels>true</generateModels>
					<dateLibrary>java8</dateLibrary>
				</configOptions>
			</configuration>
		</execution>
	</executions>
</plugin>
Steps to reproduce

mvn clean install

Related issues/PRs
Suggest a fix

The java generator should generate the OneOf Interface and the JsonSubTypes annotation should contains the object mapping.

Assignee
Assign to
Time tracking