Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

779
Views
Openapi generator angular not generating multipart formdata endpoint correctly. (useForm is false by default)

This is the endpoint I have:

@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 the generated endpoint 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"
          }
        ],
...

And here is the generated function:

 public handleFileUploadUsingPOST(file?: Array<Blob> ...) {

let headers = this.defaultHeaders;

header settings etc...

        // to determine 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 I have is 415: Unsupported media type.

I don't know how it should be generated correctly, but I changed let useForm; to true and it works, so my guess that let useForm = canConsumeForm(consumes) because canConsumeForm returns a boolean.

What should I change so it gets generated correctly?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In case anyone reads this, I haven't found the proper solution using swagger 2.0, so I updated to openapi 3.0 and that fixed the problem.

Apparently swagger 2.0 doesn't support uploading an array of files, even though the only problem was that the generated service didn't use existing functions properly.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!