Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better default types for date fields (swagger) #1026

Closed
mnisius opened this issue May 19, 2020 · 2 comments
Closed

Better default types for date fields (swagger) #1026

mnisius opened this issue May 19, 2020 · 2 comments
Milestone

Comments

@mnisius
Copy link

mnisius commented May 19, 2020

Hello again,

I'm kind of sorry to come again with this issue but I think changing the current default would improve the out of the box experience for new users a lot.

My proposal:

New Date Types

  • LocalDate -> "type": "string", "format": "date"
  • LocalDateTime -> "type": "string", "format": "date-time"
  • OffsetDateTime -> "type": "string", "format": "date-time"
  • Instant -> "type" : "integer","format" : "int32"

Old Date Types

  • util.Date -> "type" : "integer","format" : "int32"
  • sql.Date -> "type" : "integer","format" : "int32"
  • sq.TimeStamp -> "type" : "integer","format" : "int32"

The idea is that the classes that represents an actual Date will be translated to a string with the correct format. (date-time if they have time information and date if they don't. All Classes that just encapsulate an instant moment in time (like Instant, util.Date, sql.Date andTimestamp) will be translated to an integer.

@mnisius
Copy link
Author

mnisius commented May 19, 2020

Let my explain why I think that the current solution is kind of complicated.

By default enunciate 2.13.0 translates all your date types end up as "type" : "integer","format" : "int32".
I think that is not a good default because who would expect that all kind of date types will be translated to numbers?

I know it is possible to configure a different behavior if I change the enunciate.xml like this:

 <jackson dateFormat="string" disabled="false" />

But as a new User I would not now that this config parameter exist.

Then all dates types will be translated to "type": "string", "format": "date-time". This is strange for types that represents a moment in time and also for LocalDate because that type has no time information at all.
I still think this would be a way better default then going all integer.

Also it seems that the enunciate version before (I've tested 2.12.1) used a different default. Some date types would be translated as strings (without type) and others as integers.

@stoicflame stoicflame added this to the 2.14.0 milestone May 19, 2020
@stoicflame
Copy link
Owner

Fix is available in 2.13.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants