Schema with default: null becomes default("null") in generated Zod code
robogeek opened this issue · comments
Description
I have an OpenAPI spec where many of the object properties have default: null
, such as these:
programLongName:
type: string
description: Long name of program for human readability.
example: Residential Time of Use-A
nullable: true
default: null
retailerName:
type: string
description: Short name of energy retailer providing the program.
example: ACME
nullable: true
default: null
In the generated TypeScript type, they look like:
/**
* Long name of program for human readability.
*
* @example Residential Time of Use-A
* @default null
*/
programLongName?: string | null;
/**
* Short name of energy retailer providing the program.
*
* @example ACME
* @default null
*/
retailerName?: string | null;
Then in the Zod code generated by ts-to-zod they look like:
programLongName: z.string().optional().nullable().default("null"),
retailerName: z.string().optional().nullable().default("null"),
The default should be null
not "null"
.
Name | Version |
---|---|
openapi-codegen |
8.0.0 |
ts-to-zod |
3.4.1 |
Node.js | 20.10.0 |
OS + version | Ubuntu 20.04 |
Reproduction
See above
Expected result
programLongName: z.string().optional().nullable().default(null),
retailerName: z.string().optional().nullable().default(null),