glideapps / glideapps/quicktype

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

Open
#2,310 1 comment 2 reactions 0 assignees View on GitHub
bug input:JSON Schema TypeScript
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

Given the following json-schema:
```json
{
"$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:
```ts
export interface PurpleArray {
aa?: string;
bb?: string;
cc?: string;
dd?: string;
}
```

According to the json-schema spec, this is valid:
```json
[
{"aa": "aa", "bb":"bb"},
{"cc": "cc", "dd":"dd"}
]
```

But this one is not:
```
[
{"aa": "aa", "bb":"bb"},
{"aa": "aa", "cc": "cc", "dd":"dd"}
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.