Search code examples
javaswagger-uiswagger-2.0springfox

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


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 : enter image description here

Time : enter image description here

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.


Solution

  • 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