question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][Maven] importMappings not working

See original GitHub issue

Hi

maven plugin is not working as expected when trying to use an already existing class.

Here (https://openapi-generator.tech/docs/usage#target-external-models) are the instructions to generate code using a existing class.

It works when using openapi-generator client. When I execute this

openapi-generator generate \
    -i https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml \
    -g java \
    -o out \
    --language-specific-primitives=Pet \
    --import-mappings=Pet=com.yourpackage.models.Pet

Then Pet.java, as expected, does not exist in src/main/java/org/openapitools/client/model/

But when doing the same with maven plugin

<plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>4.2.2</version>
        <executions>
                <execution>
                        <goals>
                                <goal>generate</goal>
                        </goals>
                        <configuration>
                                <inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml</inputSpec>
                                <generatorName>java</generatorName>
                                <configOptions>
                                    <languageSpecificPrimitives>Pet</languageSpecificPrimitives>
                                    <importMappings>Pet=com.yourpackage.models.Pet</importMappings>
                                </configOptions>
                        </configuration>
                </execution>
        </executions>
</plugin>

Then Pet.java does exist in src/main/java/org/openapitools/client/model/ but it shouldn’t

openapi-generator-maven-plugin 4.2.2 openapi-generator-cli 4.2.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
luStopaicommented, Feb 10, 2020

Many thanks @uortiz, that was pretty hidden

I wonder if it’s possible to make this change clear in the documentation or to show some kind of warning when generating sources.

Also, I don’t really get this “backwards-compatibility” if it won’t work. I think it’s preferable to show an error instead of not complaining at all but also do nothing, it’s confusing.

Anyways, thanks again

Read more comments on GitHub >

github_iconTop Results From Across the Web

swagger-codegen-maven-plugin ignores the importmapping i ...
The importMappings and importMapping tags do not work, you are right. But there is a workaround;
Read more >
swagger-maven-plugin does not seem to support the import ...
I want to pass a list of my own import mappings to the generator using the swagger-maven-plugin so that these classes don't get...
Read more >
use imported types as query param - SmartBear Community
is it possible to use an imported type (via importMapping) not only as the return type for an endpoint, but as its parameter...
Read more >
[BUG][MAVEN] Import Mappings not working with ... - Devscope.io
OpenAPITools/openapi-generator: [BUG][MAVEN] Import Mappings not working with ... Code generation is not working after upgrade to version 6.0.1 from 5.3.0, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found