kubb icon indicating copy to clipboard operation
kubb copied to clipboard

[swagger-faker] Use ISO 8601 for Date and Time in swagger-faker when dateType='string'

Open rwhendry opened this issue 9 months ago • 1 comments

What is the problem this feature would solve?

Currently the implementation for both Date and Time in swagger-faker is

date: (type: 'date' | 'string' = 'string') => (type === 'string' ? 'faker.date.anytime().toString()' : 'faker.date.anytime()'),
time: (type: 'date' | 'string' = 'string') => (type === 'string' ? 'faker.date.anytime().toString()' : 'faker.date.anytime()'),

Which gives Date and Time format with type string will produce datetime format like 2022-07-31T01:33:29.567Z.

The enhancement that I requested is to have Date and Time format with type string will produce ISO8601 string where forDate it will looks like 2022-07-31 and Time 01:33:29.567

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

The feature is to change both Date and Time to use ISO 8601 format.

What alternatives have you considered?

No response

rwhendry avatar May 08 '24 15:05 rwhendry

Without something like dayjs or date temporal, it will be hard and I am not sure if Kubb should require a developer also to install something like dayjs. It's possible with Javascript but that will require a couple of extra lines of code to add and maintain.

stijnvanhulle avatar May 09 '24 18:05 stijnvanhulle

If that is the case, then what do you think about adding config on the swagger-faker config so users can define the function manually. For example user can define the date to be

date: moment(faker.date.anytime()).format("YYYY-MM-DD")

Or is there any alternative/suggestion?

rwhendry avatar May 20 '24 12:05 rwhendry

@rwhendry I will add a new option called dateParse where you could set it to dayjs or moment.

Behind the scenes Kubb will add the import and use

  • dayjs(faker.date.anytime()).format("YYYY-MM-DD") for format:date
  • dayjs(faker.date.anytime()).format("HH:mm:ss") for format time.

stijnvanhulle avatar May 22 '24 19:05 stijnvanhulle