evp
2 years agoRegular Visitor
@ArraySchema with items inheriting from an abstract base class not generating properly
I have the following lists annotated with @ArraySchema, and they're meant to hold subtypes of an abstract class. The openapi generated for each list is different. I would like to know how to achieve the second list's config, but without the unbound wildcard. I'm not sure what I'm doing wrong.
@ArraySchema(schema=@Schema(type="object", description = "description", oneOf = {SubType1.class}))
List<AbstractType> foo;
@ArraySchema(schema=@Schema(type="object", description = "description", oneOf = {SubType1.class}))
List<?> bar;
The abstract class's type hierarchy is fairly simple:
// AbstractType.java
public abstract class AbstractType {
protected CommonField field;
}
// SubType1.java
public class SubType1 extends AbstractType {
private String baz;
}
The generated OpenApi:
"foo": { "type": "array", "items": { "$ref": "#/components/schemas/AbstractType" } }, "bar": { "type": "array", "items": { "type": "object", "description": "description", "oneOf": [ { "$ref": "#/components/schemas/SubType1" } ] } }