Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding object only sets first encoding annotation #2958

Open
jeremyfiel opened this issue Apr 3, 2025 · 0 comments
Open

Encoding object only sets first encoding annotation #2958

jeremyfiel opened this issue Apr 3, 2025 · 0 comments

Comments

@jeremyfiel
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant