@ArraySchema with items inheriting from an abstract base class not generating properly
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023
09:44 PM
10-09-2023
09:44 PM
@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" } ] } }
Labels:
- Labels:
-
Swagger Core
2 REPLIES 2
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023
05:28 AM
10-10-2023
05:28 AM
Hey @evp ,
I'm not sure if it's possible. There might be some way to force the OpenAPI fragment you want. I can ask smarter folks than me...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023
05:49 AM
10-13-2023
05:49 AM
Hi @evp ,
What do you mean by "but without the unbound wildcard".
Do you want both like this?:
"foo": { "type": "array", "items": { "$ref": "#/components/schemas/AbstractType" } },
"bar": { "type": "array", "items": { "$ref": "#/components/schemas/AbstractType" } },
Which codegen version are you using? thanks
