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
  • #2576
Closed
Open
Issue created Apr 02, 2019 by Administrator@rootContributor

[BUG] jaxrs-cxf generator doesn't handle polymorphism

Created by: ecoquelin

Description

When running generator using gradle plugin and jaxrs-cxf, the generated code for java classes with inheritance don't contain any polymorphism annotations.

Using spring generator, I have noticed that we have the right declaration for top level class.

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = Dog.class, name = "Dog"),
  @JsonSubTypes.Type(value = Cat.class, name = "Cat"),
})
public class Animal  {

Same using jaxrs-cxf gives the following

public class Animal {

Configuration parameters are exactly the same.

openapi-generator version
buildscript {
  repositories {
    mavenLocal()
    mavenCentral()
  }
  dependencies {
    classpath "org.openapitools:openapi-generator-gradle-plugin:3.3.4"
  }
}
OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
paths:
  /animals:
    get:
      summary: Returns all animals.
      description: Optional extended description in Markdown.
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Animal'
components:
  schemas:
    Dog:
        allOf:
          - $ref: '#/components/schemas/Animal'
          - type: object
            properties:
              breed:
                type: string
    Cat:
        allOf:
          - $ref: '#/components/schemas/Animal'
          - type: object
            properties:
              breed:
                type: string                
    BigDog:
        allOf:
          - $ref: '#/components/schemas/Dog'
          - type: object
            discriminator:
              propertyName: dogType
              required:
              - dogType 
            properties:
              dogType:
                type: string
              declawed:
                type: boolean
    Animal:
        type: object
        discriminator:
          propertyName: className
        required:
        - className
        properties:
          className:
            type: string
          color:
            type: string
            default: red
Command line used for generation

gradle openApiGenerate

Steps to reproduce
  • copy the YAML provided
  • update your build.gradle with the following
buildscript {
  repositories {
    mavenLocal()
    mavenCentral()
  }
  dependencies {
    classpath "org.openapitools:openapi-generator-gradle-plugin:3.3.4"
  }
}

apply plugin: 'org.openapi.generator'

openApiValidate {
   inputSpec = "${projectDir}/src/main/resources/openapi.yaml".toString()
}

openApiGenerate {
    generatorName = "jaxrs-cxf"
    verbose = false
    validateSpec = true
    skipOverwrite = false
    withXml = false
    inputSpec = "${projectDir}/src/main/resources/test.yaml".toString()
    outputDir = "${projectDir}".toString()
    apiPackage = "myapp.rest.api"
    modelPackage = "myapp.rest.api.model"
    
    configOptions = [
        dateLibrary: "java8",
        sourceFolder: "src/main/java".toString()
    ]
}
  • run task openApiGenerate
Related issues/PRs

Haven't found any similar issue for jaxrs-cxf

Suggest a fix

Annotations are properly set with the "spring" generator

Assignee
Assign to
Time tracking