Date is not validated correctly as type: string, format: date-time
See original GitHub issueHi
I want to return the created and lastModified timestamp from the database which I define in my ORM with type Date.
If I print the response object in my express router before returning it, it looks like this:
User {
id: '1fe87c1d-5d31-4426-8757-aa5e62d2344e',
lastModified: 2020-02-21T09:26:43.603Z,
created: 2020-02-21T09:25:48.151Z,
If I call the endpoint I get the following reponse object:
{
"data": [
{
"id": "1fe87c1d-5d31-4426-8757-aa5e62d2344e",
"lastModified": "2020-02-21T09:26:43.603Z",
"created": "2020-02-21T09:25:48.151Z"
},
...
-> correctly stringified
As soon as I set the validateResponses option in the OpenApiValidator on true, I get the following error message:
{
"error": ".response.data[0].lastModified should be string, .response.data[0].created should be string,
… although it is a string in the upper example
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How do I validate a date string format in python?
import datetime >>> def validate(date_text): try: ... This raises a ValueError if the date is not formatted correctly:
Read more >Python - Validate String date format - GeeksforGeeks
Given a date format and a string date, the task is to write a python program to check if the date is valid...
Read more >Check If a String Is a Valid Date in Java - Baeldung
In the case of date inputs, we may need to verify the following: The input contains the date in a valid format, such...
Read more >How to Validate Date and Time Strings - Datatest
To validate date and time formats, we can define a helper function that uses strftime codes to check for matching strings. In the...
Read more >String is not recognized as a valid datetime - UiPath Forum
Try this. It will convert any type string date format to required string format. CDate("inputStrDate").Tostring("dd-MM-yyyy ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just hit this same issue today. It’s because the date is an object not a string. At the point the response it validated it’s still a Date object. When you print it date.toJSON() is called to convert it to a string. It’s not specific to Date, you would see this issue on any object that has a toJSON() function
The only reliable way i found to work around this is to
JSON.stringify()
thenJSON.parse()
the response body before it’s validated. This means the response body is now formatted as the destination will see the message before it’s validated.I added this code after OpenApiValidator was been installed as a workaround
Thanks a lot. The workaround worked for me too.