swagger-api / swagger-api/swagger-ui
OpenApi Spring Boot - Show date as yyyyMMdd
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
In my request model, I have a field like
@NotNull
@Schema(example = "19680228", type = "String", format = "yyyyMMdd", pattern = "([0-9]{4})(?:[0-9]{2})([0-9]{2})", required = true, nullable = false)
@JsonDeserialize(using = CustomDateDeserializer.class)
private OffsetDateTime birthDate;
Birthday is of OffsetDateTime type, however, request coming in contains only date portion in format yyyyMMdd. This is requirement and cannot be changed. And this is OK, I already take care of that with my CustomDateDeserializer and it is all working fine.
Based on OpenAPI documentation and post @ https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types, https://stackoverflow.com/questions/49379006/what-is-the-correct-way-to-declare-a-date-in-an-openapi-swagger-file, I know that OpenAPI supports ISO8601 date and date-time, in which case, no pattern is needed, and type should be provided as date or date-time.
However, in case you require some other format, the documentation states that type should be String, format should specify which format the date is in, and pattern should be provided as regex.
And this is exactly what I am doing in the above @Schema annotation.
However, when I go to https://editor.swagger.io/ and paste my .yaml file into it, the API generated for both my request model and my controller still contain incorrect formatting for birthdate and the example is not even taken into consideration:
Here is how it shows in my model:

As you can see, the format is still getting the format for OffsetDateTime and there is no example at all.
Same for my controller:
enter image description here

How do I make birthday show up as yyyyMMdd? For example, how to make it show as 19720226 in swagger editor?
I am using OpenApi/Swagger 3 in a Spring Boot application.
Q&A (please complete the following information)
- OS: Windows
- Browser: Chrome, Firefox, Brave, Edge
- Version: OpenApi/Swagger 3
- Method of installation: Spring Boot maven
- Swagger-UI version: OpenApi/Swagger 3
- Swagger/OpenAPI version: OpenApi/Swagger 3
Content & configuration
Swagger-UI configuration options:
No configuration has changed, all default. I dont know where to change it even.
Describe the bug you're encountering
described above
To reproduce...
Steps to reproduce the behavior:
described above
Expected behavior
described above
Screenshots
privided above
Additional context or thoughts
n/a
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Swagger Editor and Swagger UI with a minimal OpenAPI document reproducing the OffsetDateTime field, since the original YAML is unavailable. Compare how the schema's type, format, pattern, and example are represented for the model and controller. Done means the reproduced schema displays the requested yyyyMMdd format and example consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript, openapi, spring-boot
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100