Skip to content

[BUG][JAVA][SPRING] Bug using Multipart as array: incompatible types: java.util.List<org.springframework.web.multipart.MultipartFile> cannot be converted to org.springframework.web.multipart.MultipartFile #20678

@dgonzalezEQTIC

Description

@dgonzalezEQTIC
Description

Openapi generator for Java code does not handle well creating a multipart as array.

openapi-generator version

Lastest maven version: 7.12.0

OpenAPI declaration file content or url
  /test/v1/test:
    post:
      tags:
      - Test
      summary: multipartN
      operationId: multipartN
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                files:
                  type: array
                  items:
                    type: string
                    format: binary  ##**byte**
      responses:
        201:
          description: OK
Generation Details
    @RequestMapping(
        method = RequestMethod.POST,
        value = "/test/v1/test",
        consumes = { "multipart/form-data" }
    )
    
    default ResponseEntity<Void> _multipartN(
         @RequestPart(value = "files", required = false) List<MultipartFile> files    ) {
        return multipartN(files);
    }
 
    // Override this method
    default  ResponseEntity<Void> multipartN(MultipartFile files) {   // **This should be List<MultipartFile> files**
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
 
    }

This fails to compile because its trying to cast a list into an object.
If the same code is used but format: byte instead of binary the generated code produces a correct method that expects the List:

    @RequestMapping(
        method = RequestMethod.POST,
        value = "/test/v1/test",
        consumes = { "multipart/form-data" }
    )
    
    default ResponseEntity<Void> _multipartN(
         @Valid @RequestPart(value = "files", required = false) List<byte[]> files    ) {
        return multipartN(files);
    }

    // Override this method
    default  ResponseEntity<Void> multipartN(List<byte[]> files) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }
Steps to reproduce

Generate Java code with the above yaml example and lastest version, when compiling and generating java code an error will throw:
incompatible types: java.util.List<org.springframework.web.multipart.MultipartFile> cannot be converted to org.springframework.web.multipart.MultipartFile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions