Skip to content

[BUG]: no TS schema generated for array-based tuple schemas with prefixitems #2811

@stewartadam

Description

@stewartadam

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

  1. Create a tuple-schema using prefixItems (e.g. see spec's doc samples)
  2. npx quicktype --src-lang schema --lang typescript --just-types --src thattype.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions