swagger-maven-plugin does not seem to support the import-mappings feature in the swagger generator

1,921 views
Skip to first unread message

Rene Muñiz

unread,
Jan 25, 2016, 2:27:11 PM1/25/16
to Swagger
Hi,

Does anyone know if the swagger-maven-pluggin supports the --import-mappings parameters in the swagger generator, and documented here? ( https://github.com/swagger-api/swagger-codegen#bringing-your-own-models
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 generated by the swagger generator. I know the feature works great from the swagger codegen command line, but the swagger-maven-plugin does not seem to support passing this parameter yet.
When I configure the swagger-maven-plugin to run, it ignores the parameter. Since it is not documented in the maven README, I have tried passing it in different ways on the pom.xml configuration but it seems it is not supported. Does anyone know?

-Rene

tony tam

unread,
Jan 26, 2016, 8:41:38 PM1/26/16
to Swagger
You found a bug!  It was fixed here:


The answer to the question is that (with the updated 2.1.6-SNAPSHOT maven plugin), you add a config like such:

<configOptions>
<import-mappings>Address=foo.bar.MyAddress</import-mappings>
</configOptions>

And with that, the Address object will NOT be generated--instead, the "foo.bar.MyAddress" class will be imported and used.

Rene Muñiz

unread,
Jan 27, 2016, 4:03:28 PM1/27/16
to Swagger
Thanks Tony, 

-Rene

sh...@g2g3.digital

unread,
Apr 7, 2016, 8:17:25 AM4/7/16
to Swagger
I've just tried to make use of this and the code it generates doesn't even compile.

The generated code now has an import for the class I specified in import-mappings, but it still references the generated equivalent (without importing it).

tony tam

unread,
Apr 9, 2016, 7:10:20 PM4/9/16
to swagger-sw...@googlegroups.com
What version are you using? Please note that 2.1.6 was just released.

I have tested it in a pom.xml (attached) and it does what I would expect.

When adding this:

<import-mappings>Pet=foo.bar.Pet</import-mappings>

the previously generated Pet model is NOT generated—instead foo.bar.Pet is imported in all locations.

Perhaps you need to share your relevant info from the pom.xml to show what’s going on.

pom.xml
Reply all
Reply to author
Forward
0 new messages