2

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.

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this answers. That's exactly what I need. I update my swagger to the last version (2.3.1) and it works.
0

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

1 Comment

I'm working with Springfox swagger 2 and it use the JsonProperty annotation. My problem is with the date and time that doesn't seems to be supported currently by Springfox.
0
@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.