-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Running config-help for the jaxrs-cxf generator shows the following options for dateLibrary:
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l jaxrs-cxf
...
dateLibrary
Option. Date library to use
joda - Joda
legacy - Legacy java.util.Date
java8-localdatetime - Java 8 using LocalDateTime (for legacy app only)
java8 - Java 8 native
...When using joda, java8 and java8-localdatetime everything looks great.
However, when using legacy, instead of getting java.util.Date type for dates, I get javax.xml.datatype.XMLGregorianCalendar.
Looking at the code, it looks like DateTime is purposefuly overridden (see modules\swagger-codegen\src\main\java\io\swagger\codegen\languages\JavaCXFServerCodegen.java +79.
I don't really understand why DateTime is overridden - not sure if this is a bug or just something intentional that I don't understand. In any case, the help message and actual behavior of the generator are not consistent, so this should be treated as a bug.
Using swagger-codegen-2.2.1
Example swagger definition:
---
swagger: "2.0"
info:
version: "1.0.2"
host: "localhost:8080"
basePath: "/api"
schemes:
- "http"
paths:
/book:
get:
summary: "get a book"
description: ""
operationId: "getBook"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Book"
definitions:
Book:
type: "object"
properties:
Author:
type: "string"
Length:
type: "integer"
Published:
type: "string"
format: "date-time"
And resulting Book model:
public class Book {
@ApiModelProperty(example = "null", value = "")
private String author = null;
@ApiModelProperty(example = "null", value = "")
private Integer length = null;
@ApiModelProperty(example = "null", value = "")
private javax.xml.datatype.XMLGregorianCalendar published = null;
// Code truncated for brevity
Generated using the following command:
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./tmp/swagger.yaml -o ./tmp/output/ -l jaxrs-cxf -DdateLibrary=legacy