Forum Discussion

evp's avatar
evp
Regular Visitor
2 years ago

@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"
            }
        ]
    }
}
  • 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...

  • 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