[BUG] [PHP] Exceptions with API's with too high date-time nanosecond precision
Created by: NickUfer
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Some API's return date-times with a too high nanosecond precision for php's DateTime to parse.
Example:
▶ echo "<?php echo (new DateTime('2020-11-11T15:17:58.868722633Z'))->getTimestamp();" | php
PHP Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2020-11-11T15:17:58.868722633Z) at position 0 (2): The timezone could not be found in the database in Standard input code:1
Stack trace:
#0 Standard input code(1): DateTime->__construct()
When I trim just one decimal it works:
▶ echo "<?php echo (new DateTime('2020-11-11T15:17:58.86872263Z'))->getTimestamp();" | php
1605107878%
I experienced this problem with:
- ORY Kratos API
- reMarkable Storage API (Google Storage API)
openapi-generator version
4.3.1
OpenAPI declaration file content or url
Any API with a date-time type. Concrete: https://github.com/ory/kratos/blob/master/.schema/api.swagger.json
Suggest a fix
Add a try-catch to try to use the normal way with the DateTime constructor and if that fails parse the string to an unix timestamp with strtotime and then convert the timestamp to a DateTime.