Skip to content

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

@Til7701

Description

@Til7701

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 5eb083e (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.
#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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions