在 swagger-ui 中更改 java.sql.Time 的模型架构 [英] Change model schema for java.sql.Time in swagger-ui

查看:67
本文介绍了在 swagger-ui 中更改 java.sql.Time 的模型架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 spring-boot 应用程序中,我使用 swagger2 来记录网络服务.

In my spring-boot application, I use swagger2 to document the web-services.

我使用了一些具有 java.sql.Time 和 java.util.Date 属性的类.

I use some classes that have java.sql.Time and java.util.Date attributes.

在 swagger-ui 中,它们看起来像这样:

In swagger-ui, they appears like this :

日期:

时间:

我想修改它以显示:

  • "change_date": "YYYY-MM-DD"

  • "change_date": "YYYY-MM-DD"

"change_time": "mm:ss"

"change_time": "mm:ss"

这是我的课:

@lombok.Data
@JsonRootName("translation_value")
@ApiModel(value="TranslationValue", description="Traduction de valeur")
public class TranslationValue implements Serializable {

@JsonProperty("translation_id") private Integer translationId;
@JsonProperty("family") private String family;
@JsonProperty("language_code") private String languageCode;
@JsonProperty("value") private String value;
@JsonProperty("translation_language_code") private String translationLanguageCode;
@JsonProperty("translation_value") private String translationValue;
@JsonProperty("delivered") private String delivered;
@JsonProperty("creation_date") private Date creationDate;
@JsonProperty("creation_time") private Time creationTime;
@JsonProperty("creation_user") private String creationUser;
@JsonProperty("change_date") private Date changeDate;
@JsonProperty("change_time") private Time changeTime;
@JsonProperty("change_user") private String changeUser;
@JsonProperty("status") private String status;
@JsonProperty("orignal_translation_id") private Integer orignalTranslationId;
}

我该怎么做?我没有找到任何注释来设置格式.

How can I do this ? I don't find any annotation to set the format.

推荐答案

我们遇到了类似的问题.我们需要将 springfox 版本升级到 2.3.0 ,之前我们使用的是 springfox 2.2.2 版本.在那个旧版本的 swagger 中,@ApiModelPreporty 有一个名为example"的属性,它没有做任何事情.从 2.3.0 版本开始,这个示例"开始工作.所以我们将 springfox 版本升级到 2.3.0 之后,我们要做的就是如下图所示.

We had the similar problem. 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

这篇关于在 swagger-ui 中更改 java.sql.Time 的模型架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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