openapi-ts
openapi-ts copied to clipboard
Transformers do properly not handle fields which are both required and nullable
Description
Transformers does not check whether a field is a null. As an example: Suppose we have a schema
export type Pet = {
id?: bigint;
name: string;
createdAt: Date | null;
photoUrls: Array<string>;
/**
* pet status in the store
*/
status?: 'available' | 'pending' | 'sold';
};
Here is the transformer for it
const petSchemaResponseTransformer = (data: any) => {
if (data.id) {
data.id = BigInt(data.id.toString());
}
// May result in new Date(null), because createdAt is Date | null (but still required)
data.createdAt = new Date(data.createdAt);
return data;
};
Reproducible example or configuration
https://stackblitz.com/edit/hey-api-client-fetch-example-2simwjzc?file=src%2Fclient%2Ftransformers.gen.ts
OpenAPI specification (optional)
Inside the stackblitz link, I changed the swagger example.
System information (optional)
No response
Start a new pull request in StackBlitz Codeflow.
Thanks for reporting!
@yallxe this has been fixed in a previous release, please upgrade to the latest 🙌