[英]How do you change the date format in Swagger documentation?
I have the following in my model as described in https://stackoverflow.com/a/34750537/148844我的模型中有以下内容,如https://stackoverflow.com/a/34750537/148844 中所述
@ApiModelProperty(required = true, dataType = "java.time.LocalDate")
@JsonFormat(pattern="yyyy-MM-dd")
private Date mCreatedAt;
However Swagger is still displaying the date as a date-time-with-zone.然而,Swagger 仍然将日期显示为带区域的日期时间。 I also tried org.joda.time.LocalDate
.我也试过org.joda.time.LocalDate
。 How do I change the documentation date format example?如何更改文档日期格式示例?
Here is the documentation on the property.这是有关该物业的文件。
http://docs.swagger.io/swagger-core/v1.3.12/apidocs/index.html?com/wordnik/swagger/annotations/ApiModelProperty.html http://docs.swagger.io/swagger-core/v1.3.12/apidocs/index.html?com/wordnik/swagger/annotations/ApiModelProperty.html
SpringFox-Swagger-UI 2.9.2 SpringFox-Swagger-UI 2.9.2
I noticed this error at top of Swagger UI when run.我在运行时注意到 Swagger UI 顶部的这个错误。
Errors错误
Resolver error at paths./getTrackingDataByUserID.post.responses.200.schema.properties.items.items.properties.mCreatedAt.$ref路径解析器错误。/getTrackingDataByUserID.post.responses.200.schema.properties.items.items.properties.mCreatedAt.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/LocalDate does not exist in document无法解析引用,因为:无法解析指针:文档中不存在 /definitions/LocalDate
You need to use java.sql.Date
instead of java.time.LocalDate
.您需要使用java.sql.Date
而不是java.time.LocalDate
。 If you interested in what is mapped to what check springfox.documentation.schema.Types
.如果您对映射到什么感兴趣,请检查springfox.documentation.schema.Types
。 Here is full example:这是完整的示例:
@JsonFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(dataType = "java.sql.Date")
private Date birthDate;
,which will generate the following: ,这将生成以下内容:
properties: {
birthDate: {
type: "string",
format: "date"
}
}
Here is relevant content of springfox.documentation.schema.Types
:以下是springfox.documentation.schema.Types
相关内容:
private static final Map<Type, String> typeNameLookup = ImmutableMap.<Type, String>builder()
.put(Long.TYPE, "long")
.put(Short.TYPE, "int")
.put(Integer.TYPE, "int")
.put(Double.TYPE, "double")
.put(Float.TYPE, "float")
.put(Byte.TYPE, "byte")
.put(Boolean.TYPE, "boolean")
.put(Character.TYPE, "string")
.put(Date.class, "date-time")
.put(java.sql.Date.class, "date")
.put(String.class, "string")
.put(Object.class, "object")
.put(Long.class, "long")
.put(Integer.class, "int")
.put(Short.class, "int")
.put(Double.class, "double")
.put(Float.class, "float")
.put(Boolean.class, "boolean")
.put(Byte.class, "byte")
.put(BigDecimal.class, "bigdecimal")
.put(BigInteger.class, "biginteger")
.put(Currency.class, "string")
.put(UUID.class, "uuid")
.put(MultipartFile.class, "__file")
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.