quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

JSONSchema: "OneOf" in "Array.Items" is ignored

Open daralthus opened this issue 1 year ago • 0 comments

Given the following json-schema:

{
  "$id": "https://json-schema.hyperjump.io/schema",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
     "oneOf": [
        {"type": "object", "additionalProperties": false,  "properties": { "aa": { "type": "string" }, "bb": { "type": "string" }}},
        {"type": "object", "additionalProperties": false,  "properties": { "cc": { "type": "string" }, "dd": { "type": "string" }}}
     ]
  }
}

Quicktype generates the following incorrect types:

export interface PurpleArray {
    aa?: string;
    bb?: string;
    cc?: string;
    dd?: string;
}

According to the json-schema spec, this is valid:

[
{"aa": "aa", "bb":"bb"},
{"cc": "cc", "dd":"dd"}
]

But this one is not:

[
{"aa": "aa", "bb":"bb"},
{"aa": "aa", "cc": "cc", "dd":"dd"}
]

daralthus avatar Jun 16 '23 13:06 daralthus