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.18k stars 336 forks source link

fix(msw): when use `useDates`, convert faker values to `Date` instance #1645

Closed soartec-lab closed 1 month ago

soartec-lab commented 1 month ago

Status

READY

Description

fix #1517

when i use orverride.useDates with a schema that format is date or date-time will result in a type error so i fixed.

Before

birthDate and createdAt has type Date, but the value of make is a string, so type errors occurs.

export const getShowPetByIdResponseMock = (overrideResponse: Partial< Pet > = {}): Pet => ({birthDate: faker.date.past().toISOString().split('T')[0], createdAt: `${faker.date.past().toISOString().split('.')[0]}Z`, ...overrideResponse})

After

birthDate and createdAt are converted to Date instances

export const getShowPetByIdResponseMock = (overrideResponse: Partial< Pet > = {}): Pet => ({birthDate: new Date(faker.date.past().toISOString().split('T')[0]), createdAt: new Date(`${faker.date.past().toISOString().split('.')[0]}Z`), ...overrideResponse})

Related PRs

none

Todos

Steps to Test or Reproduce

i added test case