swagger-core
swagger-core copied to clipboard
@ArraySchema is ignored in model property (array of abstract class)
I have the following class that returns an array of abstract classes that looks like this:
@JsonPropertyOrder({"answers"})
@Schema(name = QuestionAnswers, description = "")
public final class QuestionAnswersJson extends AbstractJson {
@ArraySchema(schema = @Schema(oneOf = {XAnswerJson.class, YAnswerJson.class, //
ZAnswerJson.class, BAnswerJson.class}))
private List<AbstractAnswerJson> answers = new ArrayList<>();
public QuestionAnswersJson(@Nonnull List<AbstractAnswerJson> answers) {
answers = Preconditions.checkNotNull(answers);
}
public QuestionAnswersJson() {
// for JSON-to-Java conversion
}
public List<AbstractAnswerJson> getAnswers() {
return answers;
}
public void setAnswers(List<AbstractAnswerJson> answers) {
answers = answers;
}
}
The @ArraySchema annotation is completely ignored and the resulting class in the YAML file is an array of AbstractAnswers:
"QuestionAnswers" : {
"type" : "object",
"properties" : {
"answers" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/AbstractAnswer"
}
}
}
But I would like to have something similar to this:
"QuestionAnswers" : {
"type" : "object",
"properties" : {
"answers" : {
"type" : "array",
"items" : {
oneOf:
"$ref" : "#/components/schemas/XAnswer"
"$ref" : "#/components/schemas/YAnswer"
"$ref" : "#/components/schemas/ZAnswer"
"$ref" : "#/components/schemas/BAnswer"
}
}
}
Is that something incorrectly done on my side or is there a bug regarding @ArraySchema?