-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
I wanted to generate API Definition with the swagger-codegen-maven-plugin, for jaxrs-spec so that I receive only the models and basic API implementations (i.e., no factories). For all models that have an enum however, it produces uncompilable source code.
Swagger-codegen version
The latest stable build, 2.2.1, although I have also tried 2.2.2-SNAPSHOT but it has not made a difference.
Swagger declaration file content or url
T:
required:
- a
- c
properties:
a:
type: number
format: double
c:
type: string
state:
type: string
enum:
- initialCommand line used for generation
mvn clean io.swagger:swagger-codegen-maven-plugin:generate with the following plugin entry in the pom.xml:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<language>jaxrs-spec</language>
<output>${project.build.directory}/generated-sources/payment</output>
<configOptions>
<sourceFolder>src/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
</configOptions>
<groupId>com.product</groupId>
<artifactId>rest</artifactId>
<modelPackage>com.product.rest.model</modelPackage>
<invokerPackage>com.product.rest.invoker</invokerPackage>
<apiPackage>com.product.rest.api</apiPackage>
</configuration>
<executions>
<execution>
<id>generate-server-stubs</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Attempt to generate server stubs using the model definition above.
The generated source code then looks similar to the following:
package com.product.rest.model;
import java.time.OffsetDateTime;
import io.swagger.annotations.*;
import java.util.Objects;
public class T {
private Double amount = null;
private String currency = null;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
@XmlType(name="T")
@XmlEnum
public enum T {
{values=[initial], enumVars=[{name=INITIAL, value="initial"}]},
public String value() {
return name();
}
public static T fromValue(String v) {
return valueOf(v);
}
}
private StateEnum state = null;
...
(Ordering of imports is as-generated)
Related issues
A similar issue was reported for JaxRS-CXF in issue #3735 which was fixed a few weeks ago.
Suggest a Fix
The problem seems to be the mustache template that is used for the JaxRS-SPEC code generation. I attempted a fix but as I am wholly unfamiliar with mustache, did not get very far.