Swagger-codegen: [SPRING] bug in skipping code generation

Created on 12 May 2017  路  9Comments  路  Source: swagger-api/swagger-codegen

Description

I am using swagger-codegen-maven-plugin:2.2.2 to generate model classes for a service consumer. I just want the model class and skip generation of other codes, specially the spring boot class since it conflicts with my application's main class. I have tried following 2 configurations -

<build>
<plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>swagger.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources</output>
                            <language>spring</language>
                            <configOptions>
                                <dateLibrary>joda</dateLibrary>
                                <generateApis>false</generateApis>
                                <generateModelTests>false</generateModelTests>
                                <generateModelDocumentation>false</generateModelDocumentation>
                                <generateSupportingFiles>false</generateSupportingFiles>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
</build>

And,

<build>
<plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>swagger.yaml</inputSpec>
                            <output>${project.build.directory}/generated-sources</output>
                            <language>spring</language>
                                <generateApis>false</generateApis>
                                <generateModelTests>false</generateModelTests>
                        <generateModelDocumentation>false</generateModelDocumentation>
                                <generateSupportingFiles>false</generateSupportingFiles>
                            <configOptions>
                                <dateLibrary>joda</dateLibrary>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
</build>

Plugin runs fine for both setups, but does NOT skip generation of APIs and SupportingFiles.

Swagger-codegen version
Swagger declaration file content or url

I can re-produce the bug with the example posted here -
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen-maven-plugin/examples/swagger.yaml

Command line used for generation

mvn clean package

java8 and maven3.3.3 were used.

Steps to reproduce

1) Use either one of the plugin configurations to configure maven build.
2) run mvn clean package and check target/generated-sources folder.

Most helpful comment

you can do the following as child of configuration in your POM with 2.2.2 version of the plugin:

<environmentVariables>
    <models></models>
</environmentVariables>

This will restrict the plugin to generate model class only.

All 9 comments

The workaround I am using to side-step the conflicted bootstrap class is to add following configuration to my spring-boot-maven-plugin.

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.aditya.Boot</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The 2.2.2 release version hasn't supported the features you wanted to use as shown in your POM. I guess you're misled by the README of the master branch of the swagger-codegen-maven-plugin module.

You need to switch to https://github.com/swagger-api/swagger-codegen/tree/v2.2.2/modules/swagger-codegen-maven-plugin

If you want to taste the latest features, you get to clone and build locally.

@simingweng - thanks. Yeah, clearly README is way ahead of its time 馃槢 . Are there any snapshot releases on 2.3 with these features that I can jump to and test it?

I'm afraid it's not deployed as snapshot to maven central, you have to clone the code and do "mvn install", then the bleeding-edge version will be available locally on your machine as 2.2.3-SNAPSHOT

Another workaround - just don't use
<language>spring</language>
just use java with a supporting <library> like feign.

java is for generating a client library, spring will generate a Spring Boot based server stub. They're totally different. Do you need a client or a server?

I just needed jackson2-annotated model classes without additional dependencies like feign or jersey.
spring generates the server stub, but doesn't introduce additional packaging baggage for me.

you can do the following as child of configuration in your POM with 2.2.2 version of the plugin:

<environmentVariables>
    <models></models>
</environmentVariables>

This will restrict the plugin to generate model class only.

That does it. Thanks @simingweng

Was this page helpful?
0 / 5 - 0 ratings