Swagger-UI gives null value for @ModelAttribute having multipart form-data

595 Views Asked by At

I have an rest API whose request payload is an object(POJO). The structure of the object is defined below:

@Data
public class ExtractionRequest implements Serializable {
    private static final long serialVersionUID = -1594766216036852930L;
    public List<MultipartFile> files;
    @NotBlank
    private String documentType;
}

My API is defined as below:

@PostMapping(value = "/upload", consumes = { MediaType.APPLICATION_JSON_VALUE,
            MediaType.MULTIPART_FORM_DATA_VALUE })
    public ResponseEntity<UploadDocuments> upload(@ModelAttribute ExtractionRequest extractionRequest)
            throws MOException {
        System.out.println(extractionRequest.getFiles());
        System.out.println(extractionRequest.getDocumentType());
}

Now when I try to invoke the /upload api using Swagger-UI, it gives me null value for both. However, when I try to invoke the same api is using POSTMAN (with form data), it return the correct value.

Restriction is like I need to take the "multipart file and its type" in a POJO class.

Is @ModelAttribute not supported by Swagger? If yes, is there any alternative annotation of @ModelAttribute which can take a request payload together with file(Multipart) and other values(String, etc.)

0

There are 0 best solutions below