![](/img/trans.png)
[英]swagger @ApiModelProperty example value for List<String> property
[英]Swagger @ApiModelProperty example value null for Long
我将SpringFox和Swagger UI用于API文档。
我有一个DTO,其中有一个类型为Long的属性。 它没有99%的时间填充,因此我想通过将属性值设置为null
来在文档中证明这一事实。 所以我想在示例部分使用此JSON
{
/* ... */
"legacyId": null
}
我已经尝试过了
@ApiModelProperty(value = "legacyId", example = null)
public Long getLegacyId() {
return legacyId;
}
但是我得到一个警告“属性值必须恒定”。 我还能做什么?
如您在这里看到的,没有null的dataType。 你有两个选择
您可以定义为
@ApiModelProperty(example = "null") --> This will display as "null"
这会误导用户并可能导致NPE
@ApiModelProperty(hidden = true)
就个人而言,我更喜欢第二个,因为当spring从控制器中的UI映射json时,如果前端未传递任何内容,则它会自动为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.