poem icon indicating copy to clipboard operation
poem copied to clipboard

poem-openapi: Replace `naive-date` with `date`

Open sawi97 opened this issue 1 year ago • 2 comments

When a date type was specified in an openapi Object, it was previously set to the format naive-date, which isn't recognized by doc-generators.

This replaces the openapi text format naive-date with date, aligning with the OAS definition which uses RFC3339 full-date (which is naive by def).

It enables doc-generators (e.g. rapidoc) to generate examples when the schema contains a time::Date or chrono::NaiveDate field.

sawi97 avatar Feb 19 '24 13:02 sawi97

how about date-time? should we change together. ( I'm not familiar with openapi

attila-lin avatar Feb 20 '24 07:02 attila-lin

I believe openapi uses the same date/time definitions as json schema.

A naive date-time does not exist (yet). And I do not think it would be a good idea to set it to date-time, which is specified to contain timezone. Poem would not parse a date-time with time zone as a naive date-time, so the doc-generated examples would fail. And if there are any external input/output validators, they will most probably cause the request to fail. The same goes for time (even tough time is not in the OAS specification, but rapidoc uses it).

So in my opinion the other date/time formats are fine, at least until OAS/JSON Schema has a specification for naive formats. :)

sawi97 avatar Feb 20 '24 09:02 sawi97

Thanks for your reply!

attila-lin avatar Feb 21 '24 01:02 attila-lin

If you expect a datetime in RFC3339 format, should use OffsetDateTime instead of PrimitiveDateTime.

sunli829 avatar Mar 24 '24 02:03 sunli829

@sunli829 this PR is about date, not datetime. All date objects are naive in OAS and that is what this PR fixes.

Can you reopen and consider merging?

sawi97 avatar Mar 24 '24 08:03 sawi97