Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7942
Closed
Open
Issue created Nov 14, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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.

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache#L301-L313

Assignee
Assign to
Time tracking