摇摆日期字段与日期时间字段 [英] swagger date field vs date-time field

查看:361
本文介绍了摇摆日期字段与日期时间字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用swagger来测试我的其余api,我的实体类的一个属性是一个日期字段,我需要yyyy-mm-dd格式的日期,但是swagger模型模式将此字段显示为日期 - 时间而不是日期字段,因此它给出了时间和区域的日期。如何将此日期时间转换为日期字段?

I am using swagger to test my rest api, one of the property of my entity class is a date field for which I need the date in yyyy-mm-dd format , but swagger model schema is showing this field as date-time instead of date field, therefore it gives date with time and zone. How can I convert this date-time into date field ?

我有一个java实体类TimeEntry.java其属性之一是Date,它看起来像这样。

I have a java entity class TimeEntry.java one of its property is Date, it looks like this.

@ApiModelProperty(required = true)
@JsonFormat(pattern = DATE_FORMAT)
private Date date;

此字段,在swagger UI模型架构上,字段日期显示为date: 2016-01-08T22:34:22.337Z但我需要这个作为日期:2016-01-08。

for this field, on the swagger UI model schema, the field date displays as "date": "2016-01-08T22:34:22.337Z" but I need this as "date":"2016-01-08" .

我尝试过以下方法:

1。

@ApiModelProperty(required = true, dataType="date")  
@JsonFormat(pattern = DATE_FORMAT)   
private Date date;

2.想要跟随这段代码(覆盖OverrideConvertor类)但找不到swagger-core 1.3版本mvn repo。仅提供1.5版本 https://github.com/swagger-api/ swagger-core / wiki / overriding-models

2.Tried to follow along this code (override OverrideConvertor class) but could not find swagger-core 1.3 version mvn repo. Only available is 1.5 version https://github.com/swagger-api/swagger-core/wiki/overriding-models


  1. 显然从1.5版本开始他们删除了OverrideConvertor类
    https://groups.google.com/forum/# !topic / swagger-swaggersocket / ChiknyHZiP4

  1. Apparently from 1.5 version they have removed the OverrideConvertor class https://groups.google.com/forum/#!topic/swagger-swaggersocket/ChiknyHZiP4

请帮忙。

推荐答案

我的队友找到了解决办法。我们需要将springfox版本升级到2.3.0,之前我们使用的是springfox 2.2.2版本。在旧版本中,swagger的@ApiModelPreporty具有名为example的属性,该属性没有做任何事情。从版本2.3.0版本开始,这个示例开始工作。因此,在我们将springfox版本升级到2.3.0后,我们所要做的就是如下所示。

My team mate has found the fix. We needed to upgrade the springfox version to 2.3.0 , previously we were using springfox 2.2.2 version. In that old version swagger's @ApiModelPreporty has attribute called "example" which was not doing anything. From the version 2.3.0 version this "example" started working. So after we upgraded the springfox version to 2.3.0 , all we had to do is as shown below.

@ApiModelProperty(required = true,example = "2016-01-01")
@JsonFormat(pattern = DATE_FORMAT)
private LocalDate date; 

以下是我们发现此信息的链接:

Below is the link from where we found this information:

https://github.com/springfox/springfox/issues/998

这篇关于摇摆日期字段与日期时间字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆