-
-
Notifications
You must be signed in to change notification settings - Fork 532
Feature request: optional flag to type a field as Date for date-time or date formats #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It would be additionally helpful if you could specify where you want the changes to occur. For example, perhaps you want incoming data like query params to stay |
I could see something like this being generally-useful. What do you think about a Node.js-only API, that allows you to override the types per-object? Something like: openapiTS(mySchema, {
// other options
formatter((schemaObj) => {
if (schemaObj.format === 'date-time') {
return 'Date'; // the TypeScript “Date” type, as a string
}
// for all other schema objects, let openapi-typescript decide (return undefined)
})
}); This is something that I would want the schema authors to control, so that they can manage it. Because even in your scenario, I’d argue that |
I think that sounds like a highly flexible solution and gives users of the package a lot more control in plenty of edge-cases, mine included. |
Just added this at |
Also as an aside, please see the comment here regarding the Node.js API. The Node.js API may change to being an async-only function. But the advantage is it could fetch & parse remote schemas. Please leave a comment there if you have thoughts on that (we could even make it be a breaking 4.0 change if desired). |
Hi @drwpow , thanks for your work : ) |
I am working on a project using OpenAPI v3 and the schema contains objects which use the type string with the format
date-time
.example:
The Typescript output generated by
openapi-typescript
results in typestring
(as intended). But in our case having it parsed asDate
would save us a lot of manual unwrapping and.toISOString()
calls, asJSON.stringify
will convert the dates to ISO strings for us after callingres.send()
.Therefore, an optional flag to enable parsing strings with the
date-time
ordate
format asDate
would be very helpful!The text was updated successfully, but these errors were encountered: