我有一个继承自“SuperModel”类的“SubModel”类。我的 REST 请求返回这些类之一的对象。现在我想记录在我的 Swagger UI 中,将返回 SubModel 的对象或 SuperModel 的对象。我在谷歌上搜索了这个用例并找到了@ApiModel 注释,但它们不起作用,有人知道我在这里做错了什么吗?
@ApiModel(value = "SuperModel", discriminator = "foo", subTypes = {
SubModel.class })
public class SuperModel
{
@ApiModelProperty(required = true)
private String foo;
public String getFoo() {
return this.foo;
}
public void setFoo( String foo ) {
this.foo = foo;
}
}
@ApiModel(value = "SubModel")
public class SubModel extends SuperModel
{
private int number;
public int getNumber() {
return this.number;
}
public void setNumber( int number ) {
this.number = number;
}
}
我在 Swagger UI 中看到的只有:
SuperModel {
foo (string)
}
我在这个网站上找到了这个例子:https://github.com/swagger-api/swagger-core/wiki/Annotations#apiresponses-apiresponse但它不起作用:-(
有什么想法吗?非常感谢!
最佳答案
springfox 还不支持这个。 参见 https://github.com/springfox/springfox/issues/868
是的,这很令人困惑,因为它们确实有带有“鉴别器”和“子类型”等属性的注释,但它们不起作用。
更新:问题同时关闭(2018 年 3 月),它应该在 Springfox >= 2.9.0 中工作(我自己还没有测试过)
关于java - Swagger 不显示继承的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42858368/