Postman Collection — fields incorrectly marked as required
XVincentX opened this issue · comments
The following example object
{
"result": [
{
"id": "1",
"cat": {
"catfield1": {},
"catfield2": {
"name": "text"
}
},
"dog": {}
},
{
"id": "2",
"cat": {
"catfield1": {
"code": "text",
"name": "text"
},
"catfield2": {
"name": "text"
}
},
"dog": {
"dogfield1": "text",
"dogfield2": "text"
},
"mouse": {
"mousefield1": "text"
}
}
]
Marks dogfield1
and dogfield2
as required, although they only appear once in the array, and not on all of them
json-schema-generator indeed has issue with creating schema from arrays: krg7880/json-schema-generator#30.
I investigated quicktype
and it generates schema correctly. Here is a relevant output:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Welcome",
"definitions": {
"Welcome": {
"type": "object",
"additionalProperties": false,
"properties": {
"result": {
"type": "array",
"items": {
"$ref": "#/definitions/Result"
}
}
},
"required": [
"result"
],
"title": "Welcome"
},
"Result": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"format": "integer"
},
"cat": {
"$ref": "#/definitions/Cat"
},
"dog": {
"$ref": "#/definitions/Dog"
},
"mouse": {
"$ref": "#/definitions/Mouse"
}
},
"required": [
"cat",
"dog",
"id"
],
"title": "Result"
},
"Cat": {
"type": "object",
"additionalProperties": false,
"properties": {
"catfield1": {
"$ref": "#/definitions/Catfield1"
},
"catfield2": {
"$ref": "#/definitions/Catfield2"
}
},
"required": [
"catfield1",
"catfield2"
],
"title": "Cat"
},
"Catfield1": {
"type": "object",
"additionalProperties": false,
"properties": {
"code": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [],
"title": "Catfield1"
},
"Catfield2": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
],
"title": "Catfield2"
},
"Dog": {
"type": "object",
"additionalProperties": false,
"properties": {
"dogfield1": {
"type": "string"
},
"dogfield2": {
"type": "string"
}
},
"required": [],
"title": "Dog"
},
"Mouse": {
"type": "object",
"additionalProperties": false,
"properties": {
"mousefield1": {
"type": "string"
}
},
"required": [
"mousefield1"
],
"title": "Mouse"
}
}
}
Unfortunately, quicktype has two drawbacks:
- it weights 1.8mb
- it has async API, while our interface in http-spec is synchronous
@karol-maciaszek @XVincentX yeah quicktype is massive for our needs lol https://bundlephobia.com/result?p=quicktype@15.0.256
How much work to fix that issue in our fork of json-schema-generator? I don't think json-schema-generator is being maintained anymore 🤔
@karol-maciaszek will investigate on the matter. I do agree that QuickType is really too heavy and it's not worth (especially if it's solely because of Postman Collection support).
Might be good to chat with @marcelltoth too since he's working on integrating json-schema-generator into Studio, so maybe it makes sense to integrate our fork instead? https://github.com/stoplightio/platform-internal/pull/4273