Why does Swagger codegen tool generate different server stubs?

389 Views Asked by At

I want to generate jersey 2.0 server stub from a swagger api specification file. When using Swagger online codegen tool to generate server stub, I get a nice jersey server stub containing impl directory with clearly indicated places where I should put my business logic. Everything compiles and runs nicely.

However, when I try to generate jersey 2.0 server stub with swagger-codegen-maven-plugin, I cannot manage to get similar thing. This is the plugin config that I use in my pom.xml file:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.35</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>src/main/resources/api.yaml</inputSpec>
                <language>java</language>
                <configOptions>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                    <dateLibrary>java11</dateLibrary>
                </configOptions>
                <library>jersey2</library>
            </configuration>
        </execution>
    </executions>
</plugin>

Server stub I get this way doesn't even use Jersey annotations and is not working out of the box. Generated README.md contains instructions that aren't clear and asks me to use plugins that don't exist on maven repository.

I would like to get a similar server stub as the one I get from the online tool, but the documentation isn't really clear on how to do that.

1

There are 1 best solutions below

1
honknoodle On

As it turns out, I needed to specify the language tag to have value jaxrs-jersey, like so:

<language>jaxrs-jersey</language>