[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