Change model schema for java.sql.Time in swagger-u

2019-08-05 14:47发布

问题:

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

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

In swagger-ui, they appears like this :

Date :

Time :

I want to modify this to display :

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

  • "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.

回答1:

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



回答2:

I hope this still be helpful.

Im working with swagger jersey 2.

I think Swagger is not using the JsonProperty annotations at the moment. Still you can indicate the property name you require with the Swagger Annotation:

@ApiModelProperty(name = "index-url")

This is double work but Its the only solution I could found.

Regards