swagger @ApiModelProperty List<String> 属性的示例值
我有一个类,其中有一个属性是List<String>
public class MyClass {
....
@ApiModelProperty(position = 2)
private List<String> productIdentifiers;
....
}
此代码生成示例值,如下所示:
{
"customerId": "1001",
"productIdentifiers": [
"string"
],
"statuses": [
"NEW"
]
}
此处显示的示例值无效。我预期的示例值应该是这样的:
{
"customerId": "1001",
"productIdentifiers": [
"PRD1",
"PRD2",
"PRD3"
],
"statuses": [
"NEW"
]
}
我尝试按如下方式传递示例属性,但它没有生成正确的值:
@ApiModelProperty(position = 2, example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3" // Its not json array
@ApiModelProperty(position = 2, example = "[\"PRD1\", \"PRD2\", \"PRD3\"]")
// This generates -> "productIdentifiers": "[\"PRD1\", \"PRD2\", \"PRD3\"]" // Its too not json array
有没有办法为List属性生成正确的示例值?
更新:
我已经尝试了@nullpointer和@Zeeshan Arif提出的解决方案
@ApiModelProperty(position = 2, dataType="List", example = "PRD1, PRD2, PRD3")
private List<String> productIdentifiers;
//This generates -> `"productIdentifiers": "PRD1, PRD2, PRD3"`
更新 2 :
尝试了以下未产生正确响应的方法
@ApiModelProperty(position = 2, dataType="java.util.List<String>", example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3"
@ApiModelProperty(position = 2, dataType="String[]", example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3"
我对swagger jar的依赖性是:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId>
</exclusion>
</exclusions>
</dependency>
针对此问题更新 github 票证