OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Spring] modelNamePrefix is applied to type-mapped external types (StreamingResponseBody), generating/using RestStreamingResponseBody

Open
#21,867 2 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

Summary

When generating a Spring Boot server with openapi-generator-maven-plugin, setting Rest causes the generator to prefix and/or generate a model for an externally mapped type (StreamingResponseBody) that comes from typeMappings + importMappings. As a result, endpoints return RestStreamingResponseBody instead of StreamingResponseBody, and a RestStreamingResponseBody model is emitted (or referenced), which is incorrect and causes compile/runtime issues. The expected behavior is that externally mapped types should not be prefixed nor generated as models.

openapi-generator version

• OpenAPI Generator version: 7.15.0

OpenAPI declaration file content or url

openapi: 3.0.3
info:
  title: Streaming test
  version: 1.0.0
paths:
  /download:
    get:
      operationId: downloadFile
      responses:
        '200':
          description: Stream a file
          content:
            application/octet-stream:
              schema:
                type: string
                format: streaming   # custom format; mapped via typeMappings
Steps to reproduce
<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>repro</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/swagger.yaml</inputSpec>
        <generatorName>spring</generatorName>
        <library>spring-boot</library>
        <apiPackage>com.example.api</apiPackage>
        <modelPackage>com.example.api.model</modelPackage>
        <invokerPackage>com.example.invoker</invokerPackage>

        <!-- Prefix applied project-wide -->
        <modelNamePrefix>Rest</modelNamePrefix>

        <typeMappings>
          <!-- Map custom format to Spring's StreamingResponseBody -->
          <typeMapping>string+streaming=StreamingResponseBody</typeMapping>
        </typeMappings>
        <importMappings>
          <importMapping>StreamingResponseBody=org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody</importMapping>
        </importMappings>

        <configOptions>
          <useSpringBoot3>true</useSpringBoot3>
          <interfaceOnly>true</interfaceOnly>
          <serializableModel>true</serializableModel>
          <useOptional>true</useOptional>
          <sourceFolder>src/main/java</sourceFolder>
          <generateAliasAsModel>true</generateAliasAsModel>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>
Actual output (observed)

The generated API method signature uses RestStreamingResponseBody as the return type, e.g.:

ResponseEntity<RestStreamingResponseBody> downloadFile();

A model is generated and/or referenced for RestStreamingResponseBody under modelPackage (or the code attempts to reference it).
If generateAliasAsModel=false, the generator still prefixes the external type in signatures (RestStreamingResponseBody), leading to missing imports or invalid types.

Expected output

Since StreamingResponseBody is an externally mapped type (via typeMappings + importMappings), no model should be generated for it and no prefix should be applied. The signature should be:

ResponseEntity<StreamingResponseBody> downloadFile();

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 provided OpenAPI Generator Maven plugin reproduction with the Spring generator, then inspect how modelNamePrefix interacts with typeMappings and importMappings. Done means the generated endpoint uses StreamingResponseBody without a prefix and no RestStreamingResponseBody model is generated or referenced.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.