swagger-core
swagger-core copied to clipboard
Swagger RequestBody for list return error
If you using:
import io.swagger.v3.oas.annotations.parameters.RequestBody;
for make a documentation in RequestBody and when it takes an object/string is fine but if you provide a list or array of strings it provide whit erreor of:
java.lang.IllegalStateException: No primary or single unique constructor found for interface java.util.List
example controller code:
@PostMapping(value = "/test/task", produces = "application/json", consumes = "application/json")
@Operation(summary = "Endpoint used to store something")
public ResponseEntity<List<String>> postTest(
@Valid @RequestBody
(
description = "Details of the Item to be created",
required = true,
content = @Content(
mediaType = "application/json",
schema = @Schema(type="array", implementation = String.class),
examples = {
@ExampleObject(
name = "test1",
value = "[{\n" +
" \"id\": \"1\",\n" +
" \"test\": \"test\",\n" +
"}]",
summary = "example description")
}))
List<String> test
) {
return ResponseEntity.accepted()
.body(new ArrayList<>());
}
Can anyone have a solution for this. I dont want to go back to spring requestbody