Input Format: JSON Schema written in YAML
Output Language: typescript-zod
CLI, npm, or app.quicktype.io: "npx quicktype" using Node.js v20.12
Version: 23.0.115
Description
I've generated some JSON Schema's, some of which must use regular expressions to enforce string formats. But, the generated Zod code does not include the regex patterns.
Input Data
This file is saved as regex.yaml
$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "https://example.com/project.schema.json"
title: "Project"
description: "A product in the catalog"
type: "object"
properties:
duration1:
description: |
A string conforming with ISO8601 duration strings, enforced
by a regular expression pattern.
type: string
format: regex
pattern: '^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$'
duration2:
description: |
A string conforming with ISO8601 duration strings, enforced
by a regular expression pattern. This time without the regex format.
type: string
pattern: '^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$'
year:
description: |
String of four digits meant to represent a year
type: string
pattern: '^[0-9][0-9][0-9][0-9]$'
This is almost certainly the same issue. Two properties with type: number with minimum and maximum attributes, there is nothing in the Zod code:
station_lon:
description: |
Station center WSG84-encoded longitude in decimal degrees to at least 4 decimal places.
Valid longitudes are between -180 and 180
type: number # float(>3) default=no part 680=yes
minimum: -180
maximum: 180
station_lat:
description: |
Station center WSG84 encoded latitude in decimal degrees to at least 4 decimal places.
Valid latitudes are between -90 and 90.
type: number # float(>3) default=no part 680=yes
minimum: -90
maximum: 90
The corresponding part of the generated Zod schema is:
Issue Type
Context (Environment, Version, Language)
Input Format: JSON Schema written in YAML Output Language: typescript-zod
CLI, npm, or app.quicktype.io: "npx quicktype" using Node.js v20.12 Version: 23.0.115
Description
I've generated some JSON Schema's, some of which must use regular expressions to enforce string formats. But, the generated Zod code does not include the regex patterns.
Input Data
This file is saved as
regex.yaml
The
pattern
attribute is documented here: https://www.learnjsonschema.com/2020-12/validation/pattern/Expected Behaviour / Output
The generated Zod code should include:
This is documented at: https://zod.dev/?id=strings
Current Behaviour / Output
The generated code is:
Notice that the
regex
calls are missing.Steps to Reproduce
Using the above YAML, run:
Possible Solution
ADDENDUM - RELATED ISSUE
This is almost certainly the same issue. Two properties with
type: number
withminimum
andmaximum
attributes, there is nothing in the Zod code:The corresponding part of the generated Zod schema is:
ADDENDUM 2 -- typescript-effect
Using the above example with typescript-effect-schema gives a similar result:
Output: