简体   繁体   中英

Date format time on Spring Doc swagger API

I'm trying to generate the documentation from my springboot application using spring doc, this is some of the attributes of the class which is causing me issues:

public class user {

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date dateOfBirth;

}

With the Spring doc annotation, in the swagger i got this:

dateOfBirth* string($date-time)

"dateOfBirth": "2020-04-29T14:15:32.475Z"

while i would like to have this:

dateOfBirth* string($date)

"dateOfBirth": "2020-04-29"

How to do that? I think to be close to solution but i can't firugre out what i'm missing

I think the answer you are looking for is here: swagger date field vs date-time field

Date is an object DateTime for swagger, as it is really a DateTime object. Use the appropriate type, like LocalDate , they know how to handle that.

By the way, how would you expect Swagger to properly convert a Date Pattern into the appropriate type? It's like too much magic. Swagger relies on thing that are common practices.

The JSONFormat won't change how swagger interpret your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM