Description
Expected behavior
The generated sources compile. DefaultApi.java uses MultiArticleImporter as its
JSON request body and does not import a model that was never generated.
Actual behavior
During generation, OpenAPI Generator creates an inline schema for the multipart body
and then skips its model because skipFormModel defaults to true:
Inline schema created as createMultiArticleImporter_request.
Model createMultiArticleImporter_request not generated since it's marked as unused
(due to form parameters) and skipFormModel (global property) set to true (default)
openapi-generator version
openapi-generator:7.24.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: OpenAPI Generator Bug Repro
version: 1.0.0
paths:
/api/multi_article_importer/:
post:
operationId: createMultiArticleImporter
summary: Create a multi article importer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/MultiArticleImporter'
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
'201':
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/MultiArticleImporter'
components:
schemas:
MultiArticleImporter:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>openapi-bug-repro</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>
Minimal reproducer for openapi-generator bug:
When a requestBody defines multiple content types (application/json + multipart/form-data),
the generator emits an import for a *CreateRequest wrapper class that it never creates.
See: https://github.com/OpenAPITools/openapi-generator/issues/...
</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi-generator.version>7.24.0</openapi-generator.version>
</properties>
<dependencies>
<!-- Required for generated Spring controller interfaces -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.1.14</version>
</dependency>
<!-- Required for @Valid / @NotNull annotations in generated code -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Required for @Parameter / @Operation annotations in generated code -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.22</version>
</dependency>
<!-- Required for @JsonProperty in generated model classes -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<id>generate-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>org.example.api</apiPackage>
<modelPackage>org.example.model</modelPackage>
<configOptions>
<!-- Generate only interfaces, no full Spring Boot app needed -->
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
<!-- Keep the reproducer focused on the dangling request-model import. -->
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Generation Details
error:
[ERROR] .../target/generated-sources/openapi/src/main/java/org/example/api/DefaultApi.java:[8,25]
error: cannot find symbol
symbol: class CreateMultiArticleImporterRequest
location: package org.example.model
the generated DefaultApi.java contains:
import org.example.model.CreateMultiArticleImporterRequest; // class is never generated
The import is unused, and no CreateMultiArticleImporterRequest.java exists anywhere
under target/generated-sources/.
Steps to reproduce
mvn clean compile
Related issues/PRs
Suggest a fix
Workarounds:
- Remove the
multipart/form-data content so the operation has only one request-body type.
- Alternatively, set the global property
skipFormModel to false. This generates the
otherwise unused CreateMultiArticleImporterRequest model and makes the import resolvable.
Description
Expected behavior
The generated sources compile.
DefaultApi.javausesMultiArticleImporteras itsJSON request body and does not import a model that was never generated.
Actual behavior
During generation, OpenAPI Generator creates an inline schema for the multipart body
and then skips its model because
skipFormModeldefaults totrue:Inline schema created as createMultiArticleImporter_request.
Model createMultiArticleImporter_request not generated since it's marked as unused
(due to form parameters) and
skipFormModel(global property) set to true (default)openapi-generator version
openapi-generator:7.24.0
OpenAPI declaration file content or url
pom.xml:
Generation Details
error:
[ERROR] .../target/generated-sources/openapi/src/main/java/org/example/api/DefaultApi.java:[8,25]
error: cannot find symbol
symbol: class CreateMultiArticleImporterRequest
location: package org.example.model
the generated
DefaultApi.javacontains:import org.example.model.CreateMultiArticleImporterRequest; // class is never generated
The import is unused, and no
CreateMultiArticleImporterRequest.javaexists anywhereunder
target/generated-sources/.Steps to reproduce
mvn clean compile
Related issues/PRs
Suggest a fix
Workarounds:
multipart/form-datacontent so the operation has only one request-body type.skipFormModeltofalse. This generates theotherwise unused
CreateMultiArticleImporterRequestmodel and makes the import resolvable.