【发布时间】:2016-06-01 12:50:00
【问题描述】:
我从the documentation 知道我可以像这样注释我的 POJO:
@ApiModelProperty(value = "pet status in the store", allowableValues = "available,pending,sold")
public String getStatus() {
return status;
}
产生类似的东西:
"properties": {
...,
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
}
现在实现该方法的图像:
@ApiModelProperty(value = "pets in the store")
public Set<String> getPets() {
return pets;
}
返回商店中可用的宠物列表。例如,有一天它可能是["cats", "dogs", "songbirds"],然后当鸣禽售罄时就只是["cats", "dogs"]。
我的 API 实际上会有一个端点来获取宠物列表:
而不是使用allowableValues = "cats, dogs, songbirds",
我想用 Swagger 注释指定
该字段必须包含给定端点返回的值。也就是说,类似于:
@ApiModelProperty(value = "pets in the store", allowableValues = "/pets")
public Set<String> getPets() {...}
这是为了让我的客户端/前端知道在发出请求时可以使用哪些值,
例如,在线购买宠物。如果我有"enum": ["cats", "dogs", ..],我该怎么办
【问题讨论】:
标签: java rest swagger dropwizard jsonschema