Best way to denote time (without date) in Swagger

2020-03-25 18:51发布

问题:

What is the best way to represent a time field in a swagger specification, the closest type to denote it looks like date-time but this makes standard deserialisers to expect date field to be passed along with the time... Is there a standard or best practice to just denote time in a swagger spec that works well with the Jackson deserialisers?

Is denoting time in milliseconds/seconds and using type string in swagger an acceptable approach?

回答1:

Depending on what you're trying to represent, this may or may not be a good idea.

If you want to represent a specific timestamp, then it's probably much safer to include the date.

If the date really isn't important (eg. you want to indicate that an event takes place at 14:00 every day), then I don't believe swagger has a built in format for that. However, the swagger format field is open and swagger has support for ECMA 262 regex string patterns.