我有一類,其中有一個特性是List<String>
招搖@ApiModelProperty示例值<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
有什麼辦法,我可以生成列表正確例如值財產?
更新:
我已經試過
@ApiModelProperty(position = 2, dataType="List", example = "PRD1, PRD2, PRD3")
private List<String> productIdentifiers;
//This generates -> `"productIdentifiers": "PRD1, PRD2, PRD3"`
更新2通過@nullpointer和@Zeeshan阿里夫建議的解決方案:
嘗試下面的方法,其沒有產生適當的迴應
@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"
我的招搖罐子Maven的依賴是:
<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 ticket for this issue
請標記我的答案。謝謝 –
@Anil Bharadia你對'dataType = List「'有什麼反應?'也只是爲了精確測試,你使用了什麼樣的swagger版本/依賴關係? –
nullpointer
@nullpointer對於所有這些,我得到了」PRD1,PRD2,PRD3「我的嘗試 –