openapi-generator: [BUG][openapi-generator-maven-plugin] importmapping not respected since 5.4.0
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue? Yes, inside attached ZIP
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists? -> No, but tested with 5.4.0
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output? Expected: StreamingResponseBody, Actual: Stream
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The “importMappings” seem to have no effect with version 5.4.0. With version 5.3.1 the below configuration resulted in a “StreamingResponseBody” in the generated class. With version 5.4.0 a “Stream” class is imported but that one does not exist.
openapi-generator version
Issue occurs with openapi-generator-maven-plugin 5.4.0 and did not occur with the previous version 5.3.1.
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
openapi: 3.0.3
info:
title: Demo app
version: 1.0.0
servers:
- url: /api/v1
paths:
/demo:
get:
summary: Demo
operationId: demo
responses:
'200':
description: Demo response
content:
text/csv:
schema:
type: string
format: binary
Generation Details
Plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- With version 5.3.1 of the plugin, the generated "DemoApi.java" contains default org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody as expected -->
<!-- With version 5.4.0 of the plugin, the generated "DemoApi.java" contains "Stream", but the org.example.bug.demo.api.Stream is not created -->
<version>5.4.0</version>
<executions>
<execution>
<id>bug-demo</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>org.example.bug.demo.api</apiPackage>
<modelPackage>org.example.bug.demo.api</modelPackage>
<configOptions>
<delegatePattern>true</delegatePattern>
</configOptions>
<importMappings>
stream=org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
</importMappings>
<typeMappings>string+binary=stream</typeMappings>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Run mvn clean install on the attached demo project.
Related issues/PRs
No similar issues.
Suggest a fix
Not sure what causes the problems, but I assume it has to do with this change: https://github.com/OpenAPITools/openapi-generator/pull/11217
bug Demo application
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 27 (13 by maintainers)
Same, but for the gradle plugin
Same here
@IncPlusPlus I tried to use
typeMappingsinstead ofimportMappingssince from the documentation it is not immediately clear what the difference is.It seems like the typeMapping
DateTime= java.time.ZonedDateTimewill perform a substitution of all occurrences ofDateTimewithjava.time.ZonedDateTimein the api specification. In your casejava.time.ZonedDateTimeis not a valid identifier so it will be transformed to something likeJavatimeZonedDateTime. It seems like that option is used to solve an entirely different problem.What I am looking for is a way to skip codegen for some models and just use an import/fqn instead. Before 5.4.0 that could be done with
importMappings.@jorgerod sorry could you provide a little snip of code to clarify the case?
Thanks, S.
I previously used
importMappingto be able to use Java’sZonedDateTimetype for the OpenAPIdate-timestring format. By default, the field would be ajava.time.OffsetDateTime. The configuration used to look like this (I’m using Gradle):With that configuration, the fields would be declared in the generated file with the fully qualified
java.time.ZonedDateTimetype. Since 5.4.0, the generated field is now of type “ZonedDateTimeDto” and there’s an import statement at the top of the file now as if it’s expecting there to be a DTO with that name.My current workaround is by removing
importMappingsentirely and doing the following:Looking at the Gradle plugin’s configuration options, it seems like using only
typeMappingsshould be fine for me as a long-term solution. I guess the only reason I previously neededimportMappingswas if I didn’t want to specify the whole package name in thetypeMappingssection.The following configuration works for us:
Hi We have the same problem. For us, this feature is very important. Is there any workaround or other way to do it?
In case of a fix for this bug, would it be released in a 5.4.x version?
@wing328 @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608
Thank you very much