springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 500 forks source link

@ModelAttribute with MultiPartFile upload doesn't work as expected after update from 1.7.0 to 1.8.0 #2773

Closed plantexchen closed 1 week ago

plantexchen commented 2 weeks ago

I have a POST endpoint that accepts a DTO, and within that DTO is a multi-part file. Up until version 1.7.0 this worked fine, but since 1.8.0 the behavior in Swagger UI has become problematic for me. The code basically looks like this:

@PostMapping(value = "upload", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<Void> createFile(@ModelAttribute FileDTO dto) {
    System.out.printf("dto: file=%s, name=%s%n", dto.getFile(), dto.getName());
    return ResponseEntity.ok().build();
}
public class FileDTO {
    MultipartFile file;
    String name;
}

In Swagger UI it looks like this:

springdoc_issue_before

output in console: dto: file=org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@38e2a858, name=test

Since version 1.8.0 Swagger UI looks like this:

springdoc_issue_after

The output is still the same, i.e. we don't need to change the HTTP request, but the displayed Swagger UI form is not very comfortable and I am concerned because the generated YAML/JSON API is different than in version 1.7.0.

YAML is this in 1.7.0:

  /file/upload:
    post:
      operationId: uploadFile
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/FileDTO'
      responses:
        '200':
          description: OK
      tags:
        - file-controller
    [...]
    FileDTO:
      type: object
      properties:
        file:
          type: string
          format: binary
        name:
          type: string

and in 1.8.0 YAML is like this:

  /file/upload:
    post:
      operationId: uploadFile
      parameters:
        - in: query
          name: dto
          required: true
          schema:
            $ref: '#/components/schemas/FileDTO'
      responses:
        '200':
          description: OK
      tags:
        - file-controller
    [...]
    FileDTO:
      type: object
      properties:
        file:
          type: string
          format: binary
        name:
          type: string

Of course I could rework the endpoint, use @RequestParam and make some changes to our frontend to avoid this issue, but I'm curious if this is a real bug and if there is a patch planned or what can I do to restore the old behavior?

P.S. I am using Spring Boot 2.7.

bnasslahsen commented 1 week ago

springdoc-openapi v1.8.0 is the latest Open Source release supporting Spring Boot 2.x and 1.x. An extended support for springdoc-openapi v1 project is now available for organizations that need support beyond 2023. For more details, feel free to reach out: sales@springdoc.org

plantexchen commented 1 week ago

springdoc-openapi v1.8.0 is the latest Open Source release supporting Spring Boot 2.x and 1.x. An extended support for springdoc-openapi v1 project is now available for organizations that need support beyond 2023. For more details, feel free to reach out: sales@springdoc.org

Understood, but it is a pity that there is no workaround without rewriting the endpoint.