I have one class in which there is one property which is List<String>
public class MyClass {
....
@ApiModelProperty(position = 2)
private List<String> productIdentifiers;
....
}
This code generates the example values as following:
{
"customerId": "1001",
"productIdentifiers": [
"string"
],
"statuses": [
"NEW"
]
}
The example values here shown are not valid. My expected example values should be like:
{
"customerId": "1001",
"productIdentifiers": [
"PRD1",
"PRD2",
"PRD3"
],
"statuses": [
"NEW"
]
}
I have tried passing example attribute as following but it is not generating proper value:
@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
Is there any way I can generate proper example value for List<String>
property?
Update:
I have tried the solutions suggested by @nullpointer and @Zeeshan Arif
@ApiModelProperty(position = 2, dataType="List", example = "PRD1, PRD2, PRD3")
private List<String> productIdentifiers;
//This generates -> `"productIdentifiers": "PRD1, PRD2, PRD3"`
Update 2:
Tried following approach which did not generate proper response
@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"
my maven dependency for swagger jar is:
<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>
Update github ticket for this issue
dataType=List<String>"
? Also just to test precisely, what swagger version/dependency are you using? – Brie