OpenAPITools / OpenAPITools/openapi-generator
[BUG] modelNamePrefix should not get applied to typeMappings
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When you define a modelNamePrefix it also gets applied to the typeMappings target name. This causes that the importMappings not to match.
Example:
<modelNamePrefix>Abc</modelNamePrefix>
<typeMappings>string+binary=Resource</typeMappings>
<importMappings>Resource=org.springframework.core.io.Resource</importMappings>
generates an API class like:
import com.test.model.AbcResource;
...
public Mono<AbcResource> getTransaction(String transactionId) {
...
but I would expect:
import org.springframework.core.io.Resource;
...
public Mono<Resource> getTransaction(String transactionId) {
...
openapi-generator version
openapi-generator-maven-plugin 7.5.0
OpenAPI declaration file content or url
Maven plugin code
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<generateModelDocumentation>false</generateModelDocumentation>
<skipValidateSpec>false</skipValidateSpec>
<strictSpec>true</strictSpec>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<modelNamePrefix>Abc</modelNamePrefix>
<configOptions>
<dateLibrary>java8</dateLibrary>
<implicitHeaders>true</implicitHeaders>
<java8>true</java8>
<openApiNullable>false</openApiNullable>
<swaggerAnnotations>false</swaggerAnnotations>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
<useTags>true</useTags>
</configOptions>
</configuration>
<executions>
<execution>
<id>generate-transaction-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/spec.yaml</inputSpec>
<generatorName>java</generatorName>
<library>webclient</library>
<apiPackage>com.test.api</apiPackage>
<modelPackage>com.test.model</modelPackage>
<typeMappings>string+binary=Resource</typeMappings>
<importMappings>Resource=org.springframework.core.io.Resource</importMappings>
</configuration>
</execution>
</executions>
</plugin>
spec.yaml:
openapi: 3.0.3
info:
title: aaa
version: 1.0.0
tags:
- name: TransactionsV1
paths:
/v1/transactions/{transactionId}:
get:
tags:
- TransactionsV1
summary: abc
operationId: getTransaction
parameters:
- name: transactionId
in: path
required: true
description: The transaction id.
schema:
type: string
responses:
'200':
description: abc
content:
application/pdf:
schema:
type: string
format: binary
Generation Details
see above
Steps to reproduce
see above
Suggest a fix
Do not apply modelNamePrefix and modelNameSuffix to typeMappings target
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
Use the Maven plugin configuration and spec.yaml in the report as the reproduction entry point; inspect how modelNamePrefix, typeMappings, and importMappings are processed. Done means the Resource mapping remains unchanged by the prefix and the generated API uses org.springframework.core.io.Resource as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100