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

Marshmallow plugin doesn't document the format of fields.DateTime() correctly #814

Closed
TheBigRoomXXL opened this issue Dec 2, 2022 · 3 comments
Labels

Comments

@TheBigRoomXXL
Copy link
Contributor

Marshmallow support multiple format for DateTime:

format: Either "rfc" (for RFC822), "iso" (for ISO8601), "timestamp", "timestamp_ms" (for a POSIX timestamp) or a date format string. If None, defaults to “iso”.

I was expecting apispec to adapt documentation base on the format but apispec always default to iso format. To change this behavior , I guess the FieldConverterMixin.field2type_and_format would need to be changed but I don't know exactly how.

I don't know if that qualify as a "bug" but it would certainly be nice to have that in the future.

@lafrech lafrech added the bug label Dec 2, 2022
@lafrech
Copy link
Member

lafrech commented Dec 2, 2022

Yes, in OpenAPI "date-time" implies iso and other formats should use a specific pattern.

https://stackoverflow.com/a/49379235

Let's label this a bug.

This deserves a new field2datetime function in field_converter.py.

Help on this welcome.

Hopefully the correct regex for other formats can be found somewhere.

Users using custom format would have to define the regex themselves.

@TheBigRoomXXL
Copy link
Contributor Author

Yes, in OpenAPI "date-time" implies iso and other formats should use a specific pattern.

Yes but timestamp is a little different than custom date because it should have the type "integer" instead of "string".
Also OpenAPI format is an open field so I think we should also add 'timestamp' or 'timestamp_ms' as format .

Hopefully the correct regex for other formats can be found somewhere.

I couldn't find any regex for RFC822 so I did my own:

^((Mon|Tue|Wed|Thu|Fri|Sat|Sun), ){0,1}\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|(Z|A|M|N)|(\+|-)\d{4})$

Some example of it here: https://regex101.com/r/hOctM6/1

It's not perfect. Some DateTime string not conform with RFC822 will slip through but it's very descriptive and relatively short..

Users using custom format would have to define the regex themselves.

Yes. I think a pattern parameter inside the metadata of field is a good place to put it.

Help on this welcome.

Here is my pull request : #815. I hope it's good with you!

@sloria
Copy link
Member

sloria commented Jan 10, 2024

resolved by #815 and released in 6.4.0

@sloria sloria closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants