orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.09k stars 335 forks source link

[Feature] Allow to customize data type for dates #1432

Open rcomesan opened 5 months ago

rcomesan commented 5 months ago

What are the steps to reproduce this issue?

Set useDates to true in the output configuration:

module.exports = {
  petstore: {
    output: {
      override: {
        useDates: true,
      },
    },
  },
};

What happens?

It generates TypeScript interfaces using the standard Date data type when the schema format is 'date' or 'date-time'.

What were you expecting to happen?

I was expecting to have a way to customize the data type used here. I have a custom class that I use for dates and I'd like to import it and use that instead of the standard Date object.

I know I must handle date parsing/construction myself, but even if I do this the interfaces are defined with Date instead of my custom DateTime class.

Any other comments?

Is there a way to achieve this? If not, is there any interest in such a feature?

sloanesturz commented 5 months ago

I am interested in this feature. A similar, useful, feature would be to have separate types for OpenAPI date and date-time string formats.

SaebAmini commented 2 months ago

I was just trying to find a workaround for this as well but couldn't find any.

The doc claims "You can choose to use any Date library you want", but unless you can specify the client to use that library's type it wouldn't really be usable as the type signature would remain incorrect.