swagger-api / swagger-api/swagger-codegen

[Spring] Generated server code inconsistent for multipart/form-data request with array of attachments.

Open
#11,064 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
Swagger-codegen version

3.0.26

Swagger declaration file content or url
openapi: 3.0.0
info:  
  version: "0.1"
  title: testbug
paths:
  /testbug:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                attachment:
                  type: string
                  format: binary
                attachments:
                  items:
                    type: string
                    format: binary
      responses:
        '201':
          description: Successful response.
          content:
            text/plain:
              schema:
                type: string
Command line used for generation
java -jar .\swagger-codegen-cli-3.0.26.jar generate -l spring -i testbug.yaml -o testbug
Steps to reproduce
java -jar .\swagger-codegen-cli-3.0.26.jar generate -l spring -i testbug.yaml -o testbug

This generates following server-side code TestbugApi.java for above operation /testbug:

import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
...
public interface TestbugApi {

    @Operation(summary = "", description = "", tags={  })
    @ApiResponses(...})
    @RequestMapping(value = "/testbug",
        produces = { "text/plain" }, 
        consumes = { "multipart/form-data" }, 
        method = RequestMethod.POST)
    ResponseEntity<String> testbugPost(
      @Parameter(description = "file detail") @Valid @RequestPart("file") MultipartFile attachment, 
      @Parameter(in = ParameterIn.DEFAULT, description = "",schema=@Schema()) 
          @RequestParam(value="attachments", required=false)  List<Resource> attachments);
}

So for the single attachment it generates a parameter of type MultipartFile that contains getters to retrieve the Content-Disposition name attribute and the Content-Type header for the related MIME part (OK).

However for the list of attachments we get a list of type Resource that doesn't contain getters to retrieve the Content-Disposition name attribute and neither the Content-Type header for the related MIME part (NOK).

Related issues/PRs

Not found.

Suggest a fix/enhancement

None.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided OpenAPI declaration and swagger-codegen-cli command, then inspect the generated Spring server interface in TestbugApi.java. Compare the MultipartFile attachment parameter with the List attachments parameter; done means the generated array-of-attachments signature preserves the expected multipart file metadata access consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.