YLombardi
YLombardi

Reputation: 1785

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 :

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.

Upvotes: 2

Views: 2840

Answers (3)

Raj Kundalia
Raj Kundalia

Reputation: 123

@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.

Upvotes: 0

Sourav
Sourav

Reputation: 436

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

Upvotes: 3

cesaregb
cesaregb

Reputation: 765

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

Upvotes: 0

Related Questions