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.

date-time format field is generated as string type

See original GitHub issue

Suppose 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:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mtennoecommented, Mar 11, 2020

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 version

2reactions
mtennoecommented, Mar 11, 2020

Thanks! 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 date

Thoughts?

Read more comments on GitHub >

github_iconTop 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 >

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