I am getting following code generated inside the model:
Here the property example:
@JsonProperty("commit_time")
private org.joda.time.* commitTime = null;
Another example:
public CatalogObjectMetadata commitTime(org.joda.time.* commitTime) {
this.commitTime = commitTime;
return this;
}
I used current master and v2.2.3 tag to test the code generation.
Please find the gist here: https://gist.github.com/anonymous/95b166a38734af9accd944d8b81b0c2f
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l java --library resteasy -Djava8=true -DgroupId=group.id.name -DartifactId=swagger-client
I found a few issue searching for org.joda.time.* which address similar problems, but always as imports not as the type of a variable.
Maybe I am just using the generator wrong. But using org.joda.time.* as a type looks a bit fishy.
Thank you.
Cheers,
Tobias
@tobwiens what about using a different Java datetime lib instead?
dateLibrary
Option. Date library to use
joda - Joda (for legacy app only)
legacy - Legacy java.util.Date (if you really have a good reason not to use threetenbp
java8-localdatetime - Java 8 using LocalDateTime (for legacy app only)
java8 - Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets "java8" to true
threetenbp - Backport of JSR310 (preferred for jdk < 1.8)
Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java
@wing328 I tried to use it with -DdateLibrary=java8, but the same error occurs.
I am surprised that it works with the online generator. I guess there is a specific configuration which works, but I didn't experiment enough to find the correct one.
cc @cbornet @ePaul @bbdouglas @JFCote @sreeshas @jfiala @lukoyanov
It looks like the problem is that you have a model named LocalDateTime, which conflicts with the same-named time class in Joda (Java 7) and the built-in Java 8 time library. One quick workaround is to rename it to something else, like LocalDateAndTime. Also keep in mind that there is a built-in dateTime data type intrinsic to Swagger, which will be turned into Joda or Java 8 time classes in the Java world.
For a more general fix, I'll need to poke around and see if there is a way for the code generator to detect these kinds of duplicates and do the right thing.
I am experiencing the same problem with the following swagger definition: https://purchase.izettle.com/swagger.json
"LocalTime" : {
"type" : "object",
...
}
Which is then used later on
"localTime" : {
聽 "$ref" : "#/definitions/LocalTime"
},
Like that.
Until this gets enhanced (WIP), current options include:
adding to typeMappings options (as cli and maven plugin options or programmatically) the key/value : "LocalTime" -> "LocalTime" This will cause the model to be mapped to joda.time.LocalTime
adding importMappings options the key/value : "LocalTime" -> "org.joda.time.LocalTime" This will also cause the model to be mapped to joda.time.LocalTime
LocalTime, adding it to typeMappings or importMappingsdateTime object type.
Most helpful comment
It looks like the problem is that you have a model named
LocalDateTime, which conflicts with the same-named time class in Joda (Java 7) and the built-in Java 8 time library. One quick workaround is to rename it to something else, likeLocalDateAndTime. Also keep in mind that there is a built-indateTimedata type intrinsic to Swagger, which will be turned into Joda or Java 8 time classes in the Java world.For a more general fix, I'll need to poke around and see if there is a way for the code generator to detect these kinds of duplicates and do the right thing.