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

[BUG] [Javascript] Modify parseDate in ApiClient to support epoch time in addition to ISO-8601 #6497

Closed
tray2100 opened this issue May 30, 2020 · 0 comments

Comments

@tray2100
Copy link
Contributor

Description

The APIs from the Javascript client generated seem to receive Date values in epoch millis instead of ISO-8601. However, it seems that the APIs (specifically the constructFromObject function) doesn't handle converting from epoch millis and results in 'Invalid Date'. This is happening because the long value is being converted to a string before being passed to the Date object constructor.

The solution here would be to just check if the incoming object type and if it's numeric then just pass it on to Date without wrapping it in a string first.

openapi-generator version

4.3.1

Suggest a fix

Modify this portion of the mustache file to look like this:

  exports.parseDate = function(str) {
    if (!isNaN(str)) {
      return new Date(+str);
    }
    return new Date(str.replace(/T/i, ' '));
  };
@wing328 wing328 closed this as completed Aug 4, 2020
jimschubert added a commit that referenced this issue Aug 12, 2020
* master: (129 commits)
  [typescript-axios] add promise to bearer and oauth tokens (#7132)
  update doc
  [REQ] Added enumClassPrefix option to Go server generation (#7008)
  [Java][jersey2] Add helper methods for oneOf Java classes (#7115)
  [Kotlin][Retrofit2] fix missing import for file (#7121)
  adding handling for epoch dates in javascript ApiClient mustache file (#6497) (#6504)
  update doc
  comment out cpanm in travis
  [Kotlin] Rxjava3 support (#6998)
  [BUG][JAVA] Fix error handling in okhttp-gson async api client (#7089)
  Update to reset httpRepsonse.Body (#6948)
  [php-lumen] Set required PHP version to ^7.2.5 (#6949)
  [contrib][docs] Assert importance of title/description/repro steps (#7103)
  ISSUE-4222: Prevent conflicts with accept(s) local variables in generated Java RestTemplate ApiClient (#7101)
  [bug][core] Copy all attributes (not properties) on composed schemas when flattening models (#7106)
  [core] Add type and format properties to model of inline response (#6153)
  [PowerShell] better publishing workflow (#7114)
  [aspnetcore] Typo issues in docs and generated code (#7094)
  fix http signaure auth in build.sbt (#7110)
  fix for the issue facing spec invlolving arrayschema structure with ref (#6310)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants