Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema with default: null becomes default("null") in generated Zod code #212

Open
robogeek opened this issue Dec 4, 2023 · 0 comments
Open

Comments

@robogeek
Copy link

robogeek commented Dec 4, 2023

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),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant