简体   繁体   English

在 swagger-ui 中更改 java.sql.Time 的模型模式

[英]Change model schema for java.sql.Time in swagger-ui

In my spring-boot application, I use swagger2 to document the web-services.在我的 spring-boot 应用程序中,我使用 swagger2 来记录 Web 服务。

I use some classes that have java.sql.Time and java.util.Date attributes.我使用一些具有 java.sql.Time 和 java.util.Date 属性的类。

In swagger-ui, they appears like this :在 swagger-ui 中,它们看起来像这样:

Date :日期 : 在此处输入图像描述

Time :时间 : 在此处输入图像描述

I want to modify this to display :我想修改它以显示:

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

  • "change_time": "mm:ss" “change_time”:“mm:ss”

Here is my class :这是我的课:

@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.我没有找到任何注释来设置格式。

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. 我们需要将springfox版本升级到2.3.0,之前我们正在使用springfox 2.2.2版本。 In that old version swagger's @ApiModelPreporty has attribute called "example" which was not doing anything. 在那个旧版本中,swagger的@ApiModelPreporty具有名为“ example”的属性,它没有执行任何操作。 From the version 2.3.0 version this "example" started working. 从2.3.0版开始,此“示例”开始工作。 So after we upgraded the springfox version to 2.3.0 , all we had to do is as shown below. 因此,在将springfox版本升级到2.3.0之后,我们要做的就是如下所示。

@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 https://github.com/springfox/springfox/issues/998

I hope this still be helpful. 希望对您有所帮助。

Im working with swagger jersey 2. 我正在使用宽大的球衣2。

I think Swagger is not using the JsonProperty annotations at the moment. 我认为Swagger目前未使用JsonProperty批注。 Still you can indicate the property name you require with the Swagger Annotation: 仍然可以使用Swagger注释指示所需的属性名称:

@ApiModelProperty(name = "index-url")

This is double work but Its the only solution I could found. 这是双重工作,但这是我能找到的唯一解决方案。

Regards 问候

@ApiModelProperty(value = "description", name = "notificationExpiryDate",
            dataType = "String", example = "2022-01-16T08:42:37.484Z")
private Timestamp expiryDate;

Giving the dataType as String made me get the example as it is.将 dataType 作为 String 让我得到了这个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM