OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java] Multipart request model not generated on Spring generatorName
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The code generated for a request body of type "multipart/form-data" that contains a reference to an object model as well as the file property(binary format) is missing the object model.
openapi-generator version
6.2.1 and I also try with 6.4.0, but the result is the same
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: SEDJUDE Common
description: API de conexión a peticiones comunes
version: v1
servers:
- url: http://localhost:8080
tags:
- name: Download
description: "Descarga de documentos"
paths:
/ejemplo:
post:
summary: Ejemplo de petición multipart con objeto
requestBody:
required: true
content:
multipart/form-data: # Media type
schema: # Request payload
type: object
properties: # Request parts
id: # Part 1 (string value)
type: string
format: uuid
address: # Part2 (object)
type: object
properties:
street:
type: string
city:
type: string
profileImage: # Part 3 (an image)
type: string
format: binary
responses:
'200':
description: Respuesta exitosa
Command line used for generation
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.2.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/open-api.yml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>${project.groupId}.web.api</apiPackage>
<modelPackage>${project.groupId}.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<configOptions>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
<useSwaggerUI>true</useSwaggerUI>
<delegatePattern>false</delegatePattern>
<additionalModelTypeAnnotations>
@lombok.Data
@lombok.Builder
@lombok.AllArgsConstructor
@lombok.NoArgsConstructor
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
</additionalModelTypeAnnotations>
<useSpringController>true</useSpringController>
<interfaceOnly>true</interfaceOnly>
<useTags>true</useTags>
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
</configOptions>
<typeMappings>
<typeMapping>OffsetDateTime=java.time.LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Run mvn clean compile on a maven project that has the plugin mentioned above.
- Observe that the not-generated-object related class is not generated and the compilation fails with the following errors:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/sasanchez/Proyectos/Justicia/pms/sedjude.back-common/target/generated-sources/openapi/src/main/java/mju/ntj/commom/web/api/DefaultApi.java:[8,26] cannot find symbol
symbol: class EjemploPostRequestAddress
location: package mju.ntj.commom.dto
[ERROR] /C:/Users/sasanchez/Proyectos/Justicia/pms/sedjude.back-common/target/generated-sources/openapi/src/main/java/mju/ntj/commom/web/api/DefaultApi.java:[66,114] cannot find symbol
symbol: class EjemploPostRequestAddress
location: interface mju.ntj.commom.web.api.DefaultApi
Related issues/PRs
https://swagger.io/docs/specification/describing-request-body/multipart-requests/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied OpenAPI declaration and Maven configuration by running mvn clean compile. Start by inspecting the generated DefaultApi.java and the Spring generator's multipart request handling. Done means the referenced address model is generated under the configured DTO package and compilation succeeds without the missing EjemploPostRequestAddress errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100