swagger-codegen-maven-plugin best practices

Viewed 3091

I'm using the swagger-codegen-maven-plugin within my pom to generate a client. Here is my plugin info:

<plugins>
    <plugin>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>2.4.9</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/api.json</inputSpec>
                    <language>java</language>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Using:

java version "1.8.0_221"

Apache Maven 3.6.1

I had many errors when running mvn compile, as the package names could not be found in my repo e.g.

[ERROR] //target/generated-sources/swagger/src/main/java/io/swagger/client/model/.java:[18,23] package com.google.gson does not exist

To overcome the errors and enable a successful mvn compile, I have had to name the missing packages within my pom's dependencies e.g.

<dependencies>
    <dependency>
        <groupId>io.gsonfire</groupId>
        <artifactId>gson-fire</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

I don't believe this is best practice, as I have to specify the version myself without knowing the actual version that the source has used.

My question is, what is the best practice for generating a client using maven when there are packages which can't be resolved by the swagger-codegen-plugin? Alternatively, please advise if the resolution I have found to overcome the issue is actually the best practice in this scenario?

Thanks.

0 Answers
Related