glideapps / glideapps/quicktype
allOf in conjunction with arrays didn't works as expected (or the json schema spec intends)
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
This schema works as expected:
Working schema - click to expand!
```
{
"definition": {
"person": {
"type": "object",
"required": ["age"],
"properties": {
"age": {"type": "integer"}
}
},
"persons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"AgedPerson": {
"$ref": "#/definition/person"
}
}}}
},
"$id": "person.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "person",
"type": "object",
"properties": {
"PersonList": { "allOf": [{"$ref": "#/definition/persons"}] }
}
}
```
However, if you add a additional schema to the `allOf`-section of the `PersonList` the first schema is no longer considered.
So a schema containing code like the following, only considers the `name`property and not the properties in the referenced schema `persons`.
```
"PersonList": {
"allOf": [
{"$ref": "#/definition/persons"},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}}}}]}
```
Schema generating wrong code - click to expand!
```
{
"definition": {
"person": {
"type": "object",
"required": ["age"],
"properties": {
"age": {"type": "integer"}
}
},
"persons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"AgedPerson": {
"$ref": "#/definition/person"
}
}}}
},
"$id": "person.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "person",
"type": "object",
"properties": {
"PersonList": { "allOf": [{"$ref": "#/definition/persons"}, {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}}}}] }
}
}
```
Please let me know if I was unclear of if I could contribute additional information.
Contributor guide
Assessment
This issue has not been assessed yet.