transformer for dateTime
Description
Hey there! I did not find any documentation about custom transformers, is there a wat for me to write one that generates dateTime(luxon) types?
Thanks in avances!
Not at the moment @CorneThoes :( I'm pretty sure someone asked about this before though and it's a good feature request
@mrlubos I think it would be great idea to provide an interface in the plugin settings to transform certain types on the fly:
Something like that: (pseudocode)
{
name: '@hey-api/transformers',
dates: true,
transformations: [
{
// matching part
type: 'string',
format: 'date-time',
// implementation part
transformer: (value: unknown) {
return new Date();
},
transformedTypeName: 'Date',
}
]
},
In that case, you only would need to bother only with generating the basic transformation template and make it correct for different nesting configurations of the fields, while consumers will create the transformations on their own.
It's easier said than done, since it will require to think through how to set resulting types (which will be required even for global types and if i understand correctly is the responsibility of the typescript plugin) and on top of that figure out how to add imports for types that are custom in the project.
But still, if that is achieved you won't need to bother with the implementations of transformations.
for the reference purpose: I think, that's what I was asking for here: https://github.com/orgs/hey-api/discussions/1039#discussioncomment-11194255
@mrclrchtr sorry for being so slow fixing this!
No, no problem. I have also not created an issue because it was out of my focus. I stumbled across it again today by chance.
Thanks for active maintaining!
I have a related feature request: transformers for date don't modify type: string + format: date fields, or if they do, serialize them properly.
turning on date transformers means when you have a date string schema like this:
dateOfBirth:
type: string
format: date
description: The patient's date of birth in the format YYYY-MM-DD.
example: "1980-01-01"
and a server that only accepts RFC 3339 short dates, that server would reject what this library serializes, which appears to default to the JSON serializer for Date.