Skip to content

Encoding object only sets first encoding annotation #2958

Closed
@jeremyfiel

Description

@jeremyfiel

Describe the bug

related #532
cc @patrykpacewicz

Seems the PR that introduced this support only captures the first @Encoding definition. It's possible to have more than one.

package org.example.springbased.web;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/test")
public class TestController {

@PostMapping(value ="/first", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<String> uploadMultipartWithBody(
        @RequestBody(content = @Content(encoding = @Encoding(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE)))
        @Parameter(required = true)
        @RequestPart("file") MultipartFile file,
        @RequestBody(content = @Content(encoding = @Encoding(name = "dto", contentType = MediaType.APPLICATION_JSON_VALUE)))
        @Parameter(description = "An extra JSON payload sent with file")
        @RequestPart("dto")
        DTO dto){
        return ResponseEntity.ok("Request Accepted: " + dto.toString());
    }
}}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6'
    implementation 'org.springframework.boot:spring-boot-devtools'
}

To Reproduce
Steps to reproduce the behavior:

Expected behavior

The output should include both encoding definitions.

requestBody:
  content:
    'multipart/form-data':
      schema:
        type: object
        required:
          - dto
          - file
        properties:
          dto:
            type: string
          file:
            type: string
            format: binary
      encoding:
        file:
          contentType: application/octet-stream
        dto:
          contentType: application/json
        

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions