Hi,
we want to start using Swagger (swagger-springmvc v0.8.5) in our project.
The initial setup worked fine and the web application generates the REST documentation.
But currently we are facing problems, when using Java object which are using inheritance as Request Payload for an Api Operation.
The generated documentation shows only the properties of the abstract base class. The definitions of the derived classes respectively the resources are omitted.
I used following annotations.
In the abstract base class:
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "someEnum")
@JsonSubTypes({ @JsonSubTypes.Type(value = ClassB.class, name = "CLASS_B"),
@JsonSubTypes.Type(value = ClassC.class, name = "CLASS_C"),
@JsonSubTypes.Type(value = ClassD.class, name = "CLASS_D"),
@JsonSubTypes.Type(value = ClassE.class, name = "CLASS_E") })
@ApiModel(value = "my base model", subTypes = { ClassB.class,
ClassC.class, ClassD.class, ClassE.class })
public abstract class ClassA
{
private SomeEnum someEnum;
public void setSomeEnum ( SomeEnum someEnum)
{
this.someEnum= someEnum;
}
...
}
In the derived ClassB:
@ApiModel(value = "CLASS_B", parent = ClassA.class)
public class ClassB extends ClassA
{
private AdditionalProperty addProp;
public ClassB ()
{
this.setSomeEnum ( SomeEnum.CLASS_B );
}
}
The other derived classes are specified accordingly to the ClassB.
Generated Model Schema:
Generated Model:
ClassA
{
someEnum(string, optional)=['CLASS_B' or 'CLASS_C' or 'CLASS_D' or 'CLASS_E']
}
I searched the Swagger documentation and the Swagger Group for a solution / example. I also read the Swagger Documentation regarding to the
Model Object.
Does anyone has some glue what I am doing wrong here?
Thanks,
Daniel