Swagger-codegen: [Java, Maven] swagger-codegen-maven-plugin guide request, hints

Created on 10 May 2017  路  4Comments  路  Source: swagger-api/swagger-codegen

Description

We're using the swagger-codegen-maven-plugin to generate new models specified in the .yaml file as .java output. But it seems that, maven doesn't even run/trigger the codegen-plugin.
Using codegen-cli it's working fine (except the 'only generates models' options), but there's no 'smart' way to trigger cli through maven, am i wrong ?
We already thought about trigger a .bat / .sh script to generate the models. However it seems wrong using this kind of method.

Swagger-codegen version

Tested with version 2.1.6 and 2.2.0

Swagger-codegen-maven-plugin in maven:

                                  <plugin>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-codegen-maven-plugin</artifactId>
                    <version>2.1.6</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <inputSpec>src/main/resources/api-spec.yaml</inputSpec>
                                <language>java</language>
                                <configOptions>
                                    <sourceFolder>src/main/java</sourceFolder>
                                </configOptions>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.1.6</version>
        </dependency>
Suggest a Fix

Is there an ordinary way to generate models based on the yaml file to the maven build ? Or is it possible to use cli though maven (in a smart way) ?

Bug Swagger Codegen Maven Plugin

Most helpful comment

! Important Update !
@wing328
Using maven's <pluginManagement></pluginManagement> the swagger-codegen-maven-plugin will never be triggered. I'd consider _adding_ this important Information to the official READ.me. Otherwise maven skip the activation of the plugin. I'm still a very beginner using maven, but i guess the pluginManagement doesn't include the plugin config specifications, which required to run the plugin.

Removing the <pluginManagement> i finally got my output:
d250d99f71a94bc13896654570d60ab3

Further Information on used systems & versions:
Maven 3.5.0
Java 1.8
Spring Boot 1.3.5
swagger-codegen-maven-plugin 2.2.2

final pom:
<plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.2.2</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <environmentVariables> <models></models> </environmentVariables> <inputSpec>src/main/resources/api-spec.yaml</inputSpec> <output>${project.basedir}</output> <generateApis>false</generateApis> <generateModelTests>false</generateModelTests> <generateModelDocumentation>false</generateModelDocumentation> <generateSupportingFiles>false</generateSupportingFiles> <language>spring</language> <configOptions> <interfaceOnly>true</interfaceOnly> <skipOverwrite>true</skipOverwrite> </configOptions> </configuration> </execution> </executions> </plugin>

and:

<dependency> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.2.2</version> </dependency>

Reminder:
Using maven in a IDE (like Eclipse) without the <pluginManagement> you might get the 'plugin execution not covered by lifecycle configuration' - error.
Quick fix suggest: Window->Preferences->Maven->Errors/Warnings-> set to [ignore]

I'll still working on this project including the need of the swagger-codegen and maven. If you got questions or suggestions, just let me know.

Cheers, Timo Schwan

All 4 comments

@TimoSchwan please give the latest stable version (v2.2.2) a try

@wing328 even using the swagger-codegen-maven-plugin 2.2.2 it seems maven never triggers the plugin, using:
mvn clean compile //same for install, package

Right now, i dissociate to using swagger codegen cli and simple running a cmd.

still, my pipeline should look like this (maven, codegen-plugin):

clean -> removing exisiting files
generate-sources -> generate new models through the .yaml file
compile, etc. -> using the fresh generated files to build.

Does the codegen-plugin requires specific paramters like swagger-codegen:generate using maven ?

I keep you updated as soon as i found a working method.

! Important Update !
@wing328
Using maven's <pluginManagement></pluginManagement> the swagger-codegen-maven-plugin will never be triggered. I'd consider _adding_ this important Information to the official READ.me. Otherwise maven skip the activation of the plugin. I'm still a very beginner using maven, but i guess the pluginManagement doesn't include the plugin config specifications, which required to run the plugin.

Removing the <pluginManagement> i finally got my output:
d250d99f71a94bc13896654570d60ab3

Further Information on used systems & versions:
Maven 3.5.0
Java 1.8
Spring Boot 1.3.5
swagger-codegen-maven-plugin 2.2.2

final pom:
<plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.2.2</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <environmentVariables> <models></models> </environmentVariables> <inputSpec>src/main/resources/api-spec.yaml</inputSpec> <output>${project.basedir}</output> <generateApis>false</generateApis> <generateModelTests>false</generateModelTests> <generateModelDocumentation>false</generateModelDocumentation> <generateSupportingFiles>false</generateSupportingFiles> <language>spring</language> <configOptions> <interfaceOnly>true</interfaceOnly> <skipOverwrite>true</skipOverwrite> </configOptions> </configuration> </execution> </executions> </plugin>

and:

<dependency> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.2.2</version> </dependency>

Reminder:
Using maven in a IDE (like Eclipse) without the <pluginManagement> you might get the 'plugin execution not covered by lifecycle configuration' - error.
Quick fix suggest: Window->Preferences->Maven->Errors/Warnings-> set to [ignore]

I'll still working on this project including the need of the swagger-codegen and maven. If you got questions or suggestions, just let me know.

Cheers, Timo Schwan

@TimoSchwan thanks for sharing the findings about the pluginManagement tag. Please feel free to add a Q&A to https://github.com/swagger-api/swagger-codegen/wiki/FAQ

Was this page helpful?
0 / 5 - 0 ratings