Bug Report Checklist
Description
Worked on maven plugin version 6.2.1.
Tried with latest release 7.2.0
The generated parent class "Animal.java" doesn't contain an annotation @JsonTypeName("Animal").
openapi-generator version
OpenAPI declaration file content or url
components:
schemas:
Dog:
allOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Dog_allOf'
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Cat_allOf'
Animal:
discriminator:
propertyName: className
properties:
className:
type: string
color:
default: red
type: string
required:
- className
type: object
Dog_allOf:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
With following configuration of Maven plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.2.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/test-api.yaml</inputSpec>
<modelNamePrefix>ABC</modelNamePrefix>
<modelNameSuffix>DTO</modelNameSuffix>
<apiPackage>com.test.api</apiPackage>
<modelPackage>com.test.model</modelPackage>
<enablePostProcessFile>false</enablePostProcessFile>
<generatorName>spring</generatorName>
<additionalProperties>removeEnumValuePrefix=false</additionalProperties>
<generateSupportingFiles>false</generateSupportingFiles>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<serializableModel>true</serializableModel>
<snapshotVersion>true</snapshotVersion>
<useTags>true</useTags>
<useSpringBoot3>true</useSpringBoot3>
<generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
The generated code of Animal DTO:
package com.test.model;
import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.openapitools.jackson.nullable.JsonNullable;
import java.io.Serializable;
import java.time.OffsetDateTime;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.*;
import jakarta.annotation.Generated;
/**
* ABCAnimalDTO
*/
@JsonIgnoreProperties(
value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the className to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ABCBigCatDTO.class, name = "BigCat"),
@JsonSubTypes.Type(value = ABCCatDTO.class, name = "Cat"),
@JsonSubTypes.Type(value = ABCDogDTO.class, name = "Dog")
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-01-10T18:28:22.136625800+01:00[Europe/Berlin]")
public class ABCAnimalDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String className;
private String color = "red";
public ABCAnimalDTO className(String className) {
this.className = className;
return this;
}
/**
* Get className
* @return className
*/
@NotNull
@Schema(name = "className", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("className")
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public ABCAnimalDTO color(String color) {
this.color = color;
return this;
}
/**
* Get color
* @return color
*/
@Schema(name = "color", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("color")
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ABCAnimalDTO animal = (ABCAnimalDTO) o;
return Objects.equals(this.className, animal.className) &&
Objects.equals(this.color, animal.color);
}
@Override
public int hashCode() {
return Objects.hash(className, color);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ABCAnimalDTO {\n");
sb.append(" className: ").append(toIndentedString(className)).append("\n");
sb.append(" color: ").append(toIndentedString(color)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
Bug Report Checklist
Description
Worked on maven plugin version 6.2.1.
Tried with latest release 7.2.0
The generated parent class "Animal.java" doesn't contain an annotation @JsonTypeName("Animal").
openapi-generator version
OpenAPI declaration file content or url
With following configuration of Maven plugin
The generated code of Animal DTO:
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix