[BUG]: no TS schema generated for array-based tuple schemas with prefixitems
Issue Type
Quicktype output
Context (Environment, Version, Language)
Input Format: JSON schema Output Language: Typescript
CLI, npm, or app.quicktype.io: npm Version: 23.2.6
Description
The Tuple validation section of JSON schema describes how prefixItems should be used to validate against a array-based tuple schema. Unfortunately, npx quicktype --src-lang schema --lang typescript --just-types --src Foo.json appears to output nothing when passed such a schema.
Input Data
schemars cargo package generates these valid schemas when parsing tuple structs, for example:
#[derive Serialize, Deserialize, JsonSchema]
struct Foo(Bar, Baz)
Yields:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "...",
"type": "array",
"prefixItems": [
{
"$ref": "#/$defs/Bar"
},
{
"$ref": "#/$defs/Baz"
}
],
"$defs": {
// ... inline definitions of Bar and Baz structs
}
"minItems": 2,
"maxItems": 2
}
Expected Behaviour / Output
I expected a interface type to be generated, as done when Bar and Baz refs are placed under items instead of prefixItems:
export interface Foo {
Bar?: Bar;
Faz?: Baz;
[property: string]: any;
}
Current Behaviour / Output
Nothing is generated
Steps to Reproduce
- Create a tuple-schema using prefixItems (e.g. see spec's doc samples)
- npx quicktype --src-lang schema --lang typescript --just-types --src thattype.json
I encountered this bug with a schema exported via Pydantic from Python code. Pydantic also uses prefixItems in the schemas it generates.
My model contains a list of (string, string) pairs, which produces a object[][] type in C#, and an issue from quicktype saying "quicktype cannot infer this type because there is no data about it in the input.".
I would expect a (string, string)[] type in C#.
Bumping, also came across this from using Pydantic.