date-time format field is generated as string type
See original GitHub issueSuppose we have a Date query param
@Get()
getNextDate(@Query('date') date: Date) { .. }
A generated swagger parameter definition for query param would be
"parameters": [
{
"in": "query",
"name": "",
"required": true,
"format": "date-time",
"type": "string"
}
]
But swagger-typescript-codegen
would type it as string
GetNextDate(parameters: {
'date': string,
} & CommonRequestOptions)
And when try to use it with Date, TS error would be raised Type 'Date' is not assignable to type 'string'
e.g.
const date:Date = new Date();
const res = await cl.GetDate({date: date});
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Formatting and parsing dateTimes as strings - IBM
When a dateTime element is parsed, a field is created in the message tree that has the ESQL datatype of CURRENT_TIME or CURRENT_TIMESTAMP....
Read more >Custom date and time format strings | Microsoft Learn
Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings ......
Read more >Date format and DateTime format - xgeek
1.Use Date format method. String dateStr = Date.today().format();. System.debug('>>>>' + dateStr);. System.assertEquals(dateStr, '4/24/2015'); ...
Read more >How to convert DateTime to/from specific string format (both ...
Converting DateTime to a string: To return a DateTime as a string in "yyyyMMdd" format, you may use ToString method. Code snippet example: ......
Read more >datetime — Basic date and time types — Python 3.11.1 ...
Source code: Lib/datetime.py The datetime module supplies classes for ... Return a string representing the date, controlled by an explicit format string.
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 FreeTop 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
Top GitHub Comments
We could consider doing the string union as a backwards compatible stop-gap solution, and then remove the
| string
part when going to the next major versionThanks! Backwards compatibility is important so we could consider a solution that exposes a union type for dates, where the type would be
Date | string
, and then we could check for which type is being passed in from the caller side. The actual call would contain a string version of the date either way. This would maintain backwards compatibility, while making it easier for callers/consumers as well, where you wouldn’t have to manually do that stringification of the dateThoughts?