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.

Response validation: Automatically coerce date data type to ISO string

See original GitHub issue

Is your feature request related to a problem? Please describe. When validating responses, if the data type is a js Date object, the validation of type string with format date-time fails.

{
  updatedAt: new Date() // fails
}

{
  updatedAt: "2010-13-30T23:12:35Z" // passes
}

Describe the solution you’d like The lib should try to coerce the type to ISO string and then try validation on it.

{
  updatedAt: new Date() // should pass
}

Describe alternatives you’ve considered I have to programmatically search through all the object to find a date data type and call the toISOString method on it to pass the output validation.

Additional context None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cdimasciocommented, Dec 26, 2020

this is solved in v4.10.0, please give it a try

1reaction
cdimasciocommented, Dec 19, 2020

@pilerou has provided an option that will help solve this. please have a look at https://github.com/cdimascio/express-openapi-validator/pull/493 and provide feedback. thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Yup.date() convert date into string without timezone after ...
When I type the date in the inputs, the validation is working perfectly but the date is being returned in the format 2021-03-31T18:30:00.000Z...
Read more >
JavaScript JSON Date Parsing and real Dates - Rick Strahl
One way around this date problem is to extend the JSON parser to automatically convert the ISO string dates into real JavaScript dates....
Read more >
7. Validation, Data Binding, and Type Conversion - Spring
Spring 3 introduces a "core.convert" package that provides a general type ... For example, a Date can be represented in a human readable...
Read more >
Using automatic recognition with DATEFORMAT and ...
Describes how to automatically recognize and convert the date format or time format in your source data.
Read more >
Extra Data Types - FastAPI
Other data types¶ · Python datetime.date . · In requests and responses will be represented as a str in ISO 8601 format, like:...
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