How to generate syntactically correct JSON example for List<String> with Swagger annotation

Viewed 423

I am using springfox-boot-starter. Is there a way of handling the example value properly for a field which is List<String>?

Neither @ApiModelProperty nor @Schema generates the correct result.

import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;

public class MyRequest {
    @ApiModelProperty(dataType = "List", example = "[\"value1-1\", \"value1-2\"]")
    private List<String> list1;

    @Schema(type = "array", example = "[\"value2-1\",\"value2-2\"]")
    private List<String> list2;

    @Schema(example = "[\"value3-1\",\"value3-2\"]")
    private List<String> list3;
}

The example JSON request generated on http://localhost:8080/swagger-ui/index.html is like this:

{
  "list1": "[\"value1-1\", \"value1-2\"]",
  "list2": "[\"value2-1\", \"value2-2\"]",
  "list3": "[\"value3-1\", \"value3-2\"]"
}

instead of what I would expect

{
  "list1": ["value1-1", "value1-2"],
  "list2": ["value2-1", "value2-2"],
  "list3": ["value3-1", "value3-2"]
}

It seems like there is a bug in Springfox, see issue #3863 and issue #1855.

0 Answers
Related