swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

Home Page:http://swagger.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger RequestBody for list return error

fr3sh opened this issue · comments

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