I use openApi generator to generate apis and models for my react native frontend. I have never had any issues until today, when after generating some (unrelated) apis one of my models started to throw an error every time it has to be used in an api:
Invalid Dateat [native code]:null in toISOStringat app/screens/host/user/EmailVerificationScreen.tsx:110:20 in resend
If i go to the line indicated by the error I find my api parameter:
let parameter = { type: VerificationCodeType.Email, user: context.state.user, };
The error is thrown by user
parameter that has the following structure (generated with openApi):
export interface User { /** * * @type {number} * @memberof User */ id?: number; /** * * @type {string} * @memberof User */ name?: string; /** * * @type {string} * @memberof User */ email?: string; /** * * @type {string} * @memberof User */ phone?: string; /** * * @type {string} * @memberof User */ locale?: string; /** * * @type {Date} * @memberof User */ emailVerifiedAt?: Date; /** * * @type {Date} * @memberof User */ phoneVerifiedAt?: Date;}
In particular the problem seems to be emailVerifiedAt
where, in the generated model, it gets JSONed:
export function UserToJSON(value: User | null): any { console.log(value); if (value === undefined) { return undefined; } if (value === null) { return null; } return {'id': value.id,'name': value.name,'email': value.email,'phone': value.phone,'locale': value.locale,'email_verified_at': value.emailVerifiedAt === undefined ? undefined : (value.emailVerifiedAt.toISOString().substr(0,10)), <= this'phone_verified_at': value.phoneVerifiedAt === undefined ? undefined : (value.phoneVerifiedAt.toISOString().substr(0,10)), };}
As you can see it gets checked for undefined (this Screen is only shown when emailVerifiedAt
is null (manually swapping the checks from undefined to null doesn't change the result)) and if it's not it gets translated.
As this Screen is shown only when emailVerifiedAt
is null that error is kinda blocking.
Before opening an issue on GitHub I wanted to make sure that's not something I did wrong or that I didn't get.
Any idea on what could be the problem?
If you need something else just comment it and I'll add an edit.