OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][Spring] `@RequestParam` is used instead of `@RequestPart` in a `multipart/form-data` request when the model contains `additionalProperties`

Open
#21,457 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

@RequestParam is used instead of @RequestPart in a multipart/form-data request when the model contains an additionalProperties tag.
The @RequestPart annotation is correctly generated, if the additionalProperties are removed from the model.

openapi-generator version

Tested with release 7.13.0, 7.14.0 and commit 5eb083e5ce1dd99659fadc03d7c6e809d3077af6 (latest)

OpenAPI declaration file content or url
openapi: 3.0.3  
info:  
  title: Example API  
  version: 0.0.1  
  
paths:  
  /index/file:  
    post:  
      summary: Index new files  
      operationId: IndexFiles  
      requestBody:  
        required: true  
        content:  
          multipart/form-data:  
            schema:  
              type: object  
              required:  
                - file  
                - additionalMetadata  
              properties:  
                file:  
                  type: string  
                  format: binary  
                additionalMetadata:  
                  $ref: '#/components/schemas/additionalMetadata'  
      responses:  
        '200':  
          description: Indexing successful  
  
components:  
  schemas:  
    additionalMetadata:  
      type: object  
      required:  
        - name  
        - additionalProperties  
      properties:  
        name:   
          type: string  
      additionalProperties:  
        type: string
Generation Details
#!/bin/sh  
  
UID=$(id -u)  
GID=$(id -g)  
  
docker run --rm \  
  -u "${UID}":"${GID}" \  
  -v "${PWD}":/local openapitools/openapi-generator-cli:v7.13.0 generate \  
  -i /local/openapi.yaml \  
  -g spring \  
  --additional-properties=useSpringBoot3=true \  
  --additional-properties=interfaceOnly=true \  
  --global-property=debugOperations \  
  -o /local/target/server
Steps to reproduce
  1. generate code
  2. start server
  3. use swagger ui to send data to the endpoint
  4. get a 400 status code with the following log
2025-06-24T11:12:40.121+02:00  WARN 51062 --- [nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'additionalMetadata' for method parameter type AdditionalMetadata is not present]
Related issues/PRs

I found the following issue, but it seems to be a different problem. At least it does not mention multipart requests.
https://github.com/OpenAPITools/openapi-generator/issues/13409

Suggest a fix

The isModel field for the param is set to false, if the model contains an additionalProperties tag. If you remove the tag from the example spec, it is set to true and generated correctly.

There is a isMultipart boolean in the operation containing the params. This could be used to determine the correct annotation.

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

Start by reproducing the issue with the provided OpenAPI YAML and Spring generator command, then inspect how isModel and the operation's isMultipart value determine the generated annotation. Done means the multipart endpoint with an additionalProperties model uses @RequestPart and no longer produces the reported missing-request-parameter error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.