【问题标题】:Override swagger discerption/example using @ApiModelProperty in the inherited class fields在继承的类字段中使用 @ApiModelProperty 覆盖 swagger discerption/example
【发布时间】:2021-09-06 08:57:05
【问题描述】:

我有两门课

public class Account {
    @ApiModelProperty(example = "EUR")
    private CurrencyCode currency;
    ....// public setters and getters
}

public class SpecificAccount extends Account {
    //Here I need to override the currencie example without redefining the currency field
    @ApiModelProperty(example = "USD")  
    private CurrencyCode currency;
}

我们可以在继承类中使用 @ApiModelProperty 覆盖 swagger discerption/example 吗?

【问题讨论】:

    标签: java inheritance swagger swagger-ui


    【解决方案1】:

    您应该添加 @ApiModel 注释,类也应该为您想要记录的所有字段添加 getter。

    如果你只有 getter,那么 args 构造函数是必需的,如果你有 getter 和 setter,那么默认一个就足够了。

    @ApiModel(subTypes = {SpecificAccount.class})
    public class Account {...}
    
    @ApiModel(parent = Account.class)
    public class SpecificAccount extends Account {...}
    

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多