quicktype
quicktype copied to clipboard
[BUG]: typescript-zod can't handle top-level arrays (either no code generated at all, or only the inner element type for arrays of objects)
When the input sample data is an array, e.g a single sample input of:
[{"key":"one"},{"key":"two"}]
The generated code for most languages like Go/Rust/Haskell/C# etc will logically be a Vec/List/array etc.
But when using output language typescript-zod, it does NOT generate a Zod schema/type that is an array, only a schema/type for the internal array element type.
This is inconsistent with other languages, and makes it very hard to use the lib in a consistent way when you're expecting the generated types to match the sample data you gave it.
Simple arrays of scalars produce nothing at all
Additionally... if you give an input that is a simple array of scalar values, e.g:
[1,2,3]
or
["a","b","c"]
...then absolutely no code is generated at all, aside from the import at the top: import * as z from "zod";
Context (Environment, Version, Language)
Input Format: JSON
Output Language: typescript-zod
I'm seeing this:
- in the current NPM package:
"quicktype-core": "^23.0.171" - in previous versions
- on the https://app.quicktype.io/ website
Expected Behaviour / Output
- Match the input sample data, including when it's an array. As it does for other languages.
Current Behaviour / Output
- For arrays of objects: No array schema/type is generated. Therefore the generated type does not always match the sample data given.
- For simple arrays of scalars: no code is generated at all
Steps to Reproduce
- Go to https://app.quicktype.io/
- In source type "JSON", paste one of either:
[1,2,3]-or-[{"key":"one"},{"key":"two"}] - Pick output language:
TypeScript Zod - Note that either no code in generated, or for object arrays, there's no array type.
- Switch to other languages like Go/Haskell/Rust/C#, and you'll see that most of them give you a Vec/List/array type at the top-level