Skip to content

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

Open
@htr3

Description

@htr3

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.

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