Here is the endpoint that needs to be addressed:
@PostMapping(value = "/file-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public List<FileReference> handleFileUpload(
@RequestPart(value = "file", name = "file") MultipartFile[] file, @ApiIgnore HttpSession session) {
return service.handleFileUpload(
Arrays.stream(file).map(MultipartFileWithUUID::new).collect(Collectors.toList()),
session);
}
This is how the endpoint appears in the swagger.json (swagger 2.0):
...
"post": {
"tags": [
"damage-report-controller"
],
"summary": "handleFileUpload",
"operationId": "handleFileUploadUsingPOST",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "file",
"in": "formData",
"required": false,
"type": "array",
"items": {
"type": "file"
},
"collectionFormat": "multi"
}
],
...
Below is the function generated from the endpoint:
public handleFileUploadUsingPOST(file?: Array<Blob> ...) {
let headers = this.defaultHeaders;
header settings etc...
// determining the Content-Type header
const consumes: string[] = [
'multipart/form-data'
];
const canConsumeForm = this.canConsumeForm(consumes);
let formParams: { append(param: string, value: any): any; };
let useForm = false;
...
if (useForm) {
formParams = new FormData();
} else {
formParams = new HttpParams({encoder: this.encoder});
}
...
}
The error message received is 415: Unsupported media type.
Although unsure of the correct generation method, setting let useForm;
to true resolved the issue.
It seems that
let useForm = canConsumeForm(consumes)
since canConsumeForm
returns a boolean.
What adjustments should be made for accurate generation?