I have a Spring Boot app with REST API, and in one of the request object, I declared a field which is supposed to hold a date in the format DDMMYYYY:
@Parameter(required = true, example = "20022022")
@Schema(required = true, type = "date", format = "ddmmyyyy", example = "20022022")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "ddMMyyyy")a
@JsonDeserialize(using = LocalDateDeserializer.class)
@NotNull
private LocalDate valueDate;
In the Swagger UI, the example value of this field in the request body is always shown as below (current date in the format YYYY-MM-DD).
{
...
"valueDate": "2022-03-17"
}
I have this in my pom.xml:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
</dependency>
How can I make the Swagger UI display the example date in the format DDMMYYYY? As you can see in my codes above, I put in @Parameter and @Schema but I really don't know how they work.
The problem lies in the format. The format is only valid if we use the English format. if we want to use dd/mm/yyyy we can't put format in the annotation. for this reason we must use the annotation without the format and it has worked for me using localDate
@Schema(type = "string", pattern = "dd-MM-yyyy", example = "17-02-2020")
private LocalDate fecha;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With