quicktype
quicktype copied to clipboard
[BUG]: Cannot fetch external links from $ref due inputStream.once error
When generating an output in Go, Java or Python for a JsonSchema that contains an external link reference using the $ref key, Quicktype should resolve it by fetching that URL to download the schema. Still, it's showing the following error instead:
Error: Cannot read from file or URL https://raw.githubusercontent.com/cloudevents/spec/v1.0.2/cloudevents/formats/cloudevents.json: TypeError: inputStream.once is not a function
Debugging, I discovered that the inputStream.once appears as undefined on node_modules/quicktype-core/dist/input/io/get-stream/index.js line 25 when the getStream function is invoked from a ReadableStream.
Important note: to get the error logs of this issue, I had to add:
console.error(`Error fetching schema for ${address}: ${e}`);
on file: node_modules/quicktype-core/dist/input/JSONSchemaStore.js line 36 (where the //FIXME is)
Important note: this issue is not reproducible in lower versions like 23.0.106.
Issue Type
Issue with input parsing of JSON schemas with external link references (using $ref)
Context (Environment, Version, Language)
Input Format: JSONSchema Output Language: Go, Java, Python
CLI, npm, or app.quicktype.io: npm package Version: 23.0.170
Description
Autogenerate code to use JSON schemas in different languages like Go, Java or Python.
In lower versions of the Quicktype package, like 23.0.106, this issue does not occur, and everything works as expected, but updating to the latest (23.0.170) reproduced the issue.
Input Data
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "test schema",
"type": "object",
"allOf": [
{
"$ref": "https://raw.githubusercontent.com/cloudevents/spec/v1.0.2/cloudevents/formats/cloudevents.json"
}
]
}
Expected Behaviour / Output
As it happens with lower versions, it should generate the code in the expected language correctly.
Current Behaviour / Output
Outputs an error and doesn't generate the code.
Steps to Reproduce
- Using quicktype as npm package dependency version 23.0.170
- Running an npm script with "quicktype -s schema test_schema.json -o schema.go" where
test_schema.jsonhas an external link (similar to the input data provided).