-
Notifications
You must be signed in to change notification settings - Fork 53
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
DateTime string formats / ISO 8601 #16
Comments
Hi @jwbrew, My guess is that UTCTime uses this format to specifically indicate that the time zone is always As for |
Previously ToParamSchema ZonedTime instance used custom format instead of OpenAPI default "date-time". Partially fixes #16.
Previously ToParamSchema ZonedTime instance used custom format instead of OpenAPI default "date-time". Partially fixes #16.
I've changed |
Yup I think that makes complete sense. IIRC I remember thinking something similar some time after posting the original comment. Thanks for making the change to |
You are welcome! I'll keep this issue open for some time, to think about it once again later. |
We've just run across this and I wonder whether @maksbotan you've had a chance to think about this some more. I'm not convinced that the benefit of the client knowing that the timezone is always UTC for |
Well, that makes sense. After all, always- BTW, did you consider using UNIX timestamps instead of strings? IMO that representation is far more convenient. |
Assuming the PR is as simple as I'm imagining, I'll try to find the time soon, yes. I didn't consider UNIX timestamps. We want to store YYYY-MM-DD and HH:MM:SS uniformly on the server side as UTC and then use the client's browser to render those dates+times as appropriate for the client's locale. There's a straightforward way (or should be, per my argument above) to go from I'm all ears though if you think there's a better/simpler way to achieve this with UNIX timestamps. |
I think it's a matter of personal preference. For me timestamps are better, but it may not suit you. We always expose datetime in our API as an integer — UNIX timestamp (or timestamp*1000 for millisecond precision), which by definition is always in UTC. It's then the client's (e.g. JS application in browser) responsibility to display it in any format and in any timezone. IMO there is no possibility to parse such date wrongly. And, for me, number (UTCTime) -> string (haskell) -> string (client) -> number (Date in js) roundtrip is weird — what do we need the intermediate string for? |
I'm using Servant & OpenAPI to generate a schema for code generation via openapi-generator, targeting Dart as a client language.
The current implmentations of
declareNamedSchema
forUTCTime
, andtoParamSchema
forUCTime
andZonedTime
generate a schema oftype: string
with a customformat
as a specific representation of each type. This breaks codegen in the Dart client, as it defines the required type as aString
where aDateTime
would be more appropriate. This seems to be down to theformat
being a custom representation, rather than one of openapi3's built-in format values.Given the custom formats as currently returned (
yyyy-mm-ddThh:MM:ssZ
andyyyy-mm-ddThh:MM:ss+hhMM
) are (as far as I can see) ISO8601 - and therefore openapi3 date-time compliant, I would like to open a PR that changes the implementationdeclareNamedSchema
forUTCTime
, andtoParamSchema
forUTCTime
andZonedTime
to returnformat: "date-time"
.Is this a reasonable thing to do?
As ever with matters involving dates and times the devil is hiding in every detail and I expect there's a subtle detail I've missed here. Hopefully not however, as these changes help avoid wrapping a whole load of types to generate the right schema!
The text was updated successfully, but these errors were encountered: