question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserializing OpenAPI date and datetimes as JavaScript Date objects

See original GitHub issue

I would like to add an option to the library, so that the user can deserialize date and datetime objects (both have type string and format date and date-time, respectively) as JavaScript Date object.

I have already tested it and this change in scalar.ts seems to actually be the only change needed (to be added inside the string case statement):

      if(item.format === 'date' || item.format === 'date-time') {
        return {
          value: 'Date' + nullable,
          isEnum: false,
          type: 'string',
          imports: [],
          schemas: [],
        };
      }

This would only support ISO 8601 dates and date times (default in the OpenAPI specification) but that is what most of the people use in the REST APIs these days.

However, there will also be change needed in the Axios instance, so that dates are properly deserialized as Date objects (currently these are strings).

Would you be open for such change? Do you think we should make it optional, via dedicated field in the configuration object?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
anymaniaxcommented, May 23, 2021

Need to be reimplemented since v5. I will do it if you are still interested or someone else?

1reaction
mellowarecommented, Feb 2, 2022

+1 for this, this is what openapi-generator does it makes then Date objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript: Dates Are Not Deserialized · Issue #2776 - GitHub
The code it generates requires an input parameter of a string , but then tries to call a function on it as if...
Read more >
Handling invalid date string format from consumed open api in ...
String '2020-11-23 16:15:57Z' was not recognized as a valid DateTime. I already have a custom json converter I had to write for an...
Read more >
Dates in OpenAPI Files | Baeldung
Let's see how to declare dates in an OpenAPI file, in this case, implemented with Swagger.
Read more >
Maintaining JavaScript Date Values During Deserialization ...
First, let's take a quick look at the natural behavior of Date objects in the serialization-deserialization life-cycle. In the following demo, ...
Read more >
Package com.ibm.cloud.sdk.core.util
This class handles the serialization and deserialization of Date instances that should be interpretted as OpenAPI "date-time" values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found