编程语言
首页 > 编程语言> > java – Swagger不显示继承的对象

java – Swagger不显示继承的对象

作者:互联网

我有一个继承自“SuperModel”类的“SubModel”类.我的REST请求返回其中一个类的对象.现在我想在我的Swagger UI中记录将返回SubModel的对象或SuperModel的对象.我用Google搜索了这个用例并找到了@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

是的,这很令人困惑,因为它们确实有“discriminator”和“subTypes”等属性的注释,但它们不起作用.

标签:java,swagger,swagger-ui
来源: https://codeday.me/bug/20190705/1392004.html