I have a FormTemplateElement class which has a couple of subtypes. I want the schema generation to happen using solely the @Schema annotation. However Swagger is also parsing the Jackson annotations. Is there a way to prevent this?
I want to use the Jackson annotations for serialization and deserialization purpose, that's why I can't remove it.
I am using SpringDoc version 2.3.0 and jackson version 2.16.0.
@Schema(
discriminatorProperty = "formTemplateElementType",
name = "FormTemplateElement",
discriminatorMapping = {
@DiscriminatorMapping(value = "ShortTextFormElement", schema = ShortTextFormElement.class),
@DiscriminatorMapping(value = "LongTextFormElement", schema = LongTextFormElement.class),
},
subTypes = {
ShortTextFormElement.class,
LongTextFormElement.class,
}
)
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "formTemplateElementType",
visible = false
)
@JsonSubTypes(
{
@JsonSubTypes.Type(value = ShortTextFormElement.class),
@JsonSubTypes.Type(value = LongTextFormElement.class),
})
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class FormTemplateElement {
@NotEmpty
UUID id;
@NotEmpty
FormTemplateElementType formTemplateElementType;
@NotEmpty
Boolean isRequired;
@NotEmpty
Boolean isHidden;
}
The main reason I wanted a solution for this is I was using the OAS3 for code generation. Turns out polymorphism is difficult using @JsonSubtypes in my use case (I am using open-api cli generator for typescript fetch). I kinda did a workaround where I am using @Schema annotation when I am generating the code using the cli and @JsonSubType for when I am actually running the spring boot backend.