OpenAPITools / OpenAPITools/openapi-generator

[JAVA] Incorrect method signature generated for uploadFiles when using interfaceOnly=true and delegatePattern=true

Open
#20,945 0 comments 0 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

Description
When generating Spring Boot code with interfaceOnly=true and delegatePattern=true, the generated method signature in the delegate interface is incorrect. Specifically:

The _uploadFiles method in the API interface correctly accepts a List for the files parameter.

However, the uploadFiles method in the delegate interface incorrectly accepts a single MultipartFile instead of List.

This mismatch causes compilation errors and prevents the generated code from being usable.

Code Examples
Generated API Interface (Correct)

default ResponseEntity _uploadFiles(
@Parameter(name = "ms_name", description = "Name of the microservice") @Valid @RequestParam(value = "ms_name", required = false) String msName,
@Parameter(name = "files", description = "Array of files to upload") @RequestPart(value = "files", required = false) List files
) {
return uploadFiles(msName, files);
}

Generated Delegate Interface (Incorrect)
// Override this method
default ResponseEntity uploadFiles(String msName, MultipartFile files) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

Expected Behavior
The uploadFiles method in the delegate interface should have the same signature as the _uploadFiles method in the API interface. Specifically:

The files parameter should be of type List instead of MultipartFile.

Expected Delegate Interface

// Override this method
default ResponseEntity uploadFiles(String msName, List files) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

OpenAPI Declaration File Content
Here’s a minimal OpenAPI specification (swaggerapi.yaml) to reproduce the issue:

openapi: 3.0.0
info:
title: File Upload API
version: 1.0.0
paths:
/upload:
post:
summary: Upload multiple files
operationId: uploadFiles
parameters:
- name: ms_name
in: query
schema:
type: string
description: Name of the microservice
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
files:
type: array
items:
type: string
format: binary
responses:
'200':
description: Files uploaded successfully

Generation Details
OpenAPI Generator Version: 7.1.0

Generator Name: spring

Configuration:

org.openapitools
openapi-generator-maven-plugin
7.1.0


generate-api

generate


${project.basedir}/src/main/resources/swaggerapi.yaml
spring
${project.build.directory}/generated-sources/api
com.builder.api
com.builder.model
com.builder.client

true
true
true
true
true
java8





Steps to Reproduce
Use the provided swaggerapi.yaml file.

Configure the OpenAPI Generator Maven plugin as shown above.

Run the Maven build (mvn clean install).

Check the generated code in the target/generated-sources/api directory.

Observe the incorrect method signature in the delegate interface.

Related Issues/PRs
I searched the OpenAPI Generator repository and did not find any existing issues or PRs related to this specific problem.

Suggest a Fix
The issue appears to be in the template or logic used to generate the delegate interface. Specifically:

The files parameter in the delegate interface should match the files parameter in the API interface (List instead of MultipartFile).

A potential fix would be to update the template responsible for generating the delegate interface to ensure the parameter types are consistent.

Additional Information
OpenAPI Generator Version: 7.1.0

Java Version: 17

Spring Boot Version: 3.x

Validation: The OpenAPI specification was validated using Swagger Editor and is correct.

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 running the Maven generation flow with the supplied swaggerapi.yaml and inspect the generated API and delegate interfaces under target/generated-sources/api. Trace how the spring generator handles multipart array parameters with interfaceOnly and delegatePattern enabled; done means the delegate signature matches the API signature and the generated project compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring, spring-boot
Domain
api, backend, tooling
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.