Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringFox Swagger and LocalTime

Anybody knows how to format LocalTime in Springfox? Converting to ISO format works for LocalDate with this setting to ObjectMapper

.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

But for LocalTime I'm still getting this in example and model of swagger-ui

"time": {
  "hour": "string",
  "minute": "string",
  "nano": 0,
  "second": "string"
}

I have read something that swagger spec do not use time format. Is this somewhat connected?

like image 441
Zveratko Avatar asked Apr 21 '17 06:04

Zveratko


1 Answers

Springfox does not know anything about the serialization features used, nor is there a good way to ask Jackson to figure it out.

However, you can help springfox along by providing model substitution rules. These are basically a way to change the schema of the model that is rendered in the specificiation. In your case a date/time would be represented as a time stamp which is really a long.

So in your Docket you would add a directModelSubstitute to substitute the LocalTime with Long :

docket.directModelSubstitute(LocalTime.class, Long.class)
like image 172
Dilip Krishnan Avatar answered Oct 13 '22 22:10

Dilip Krishnan