Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Cannot fetch external links from $ref due inputStream.once error #2613

Open
sergialonsaco opened this issue Jun 3, 2024 · 0 comments
Labels

Comments

@sergialonsaco
Copy link

sergialonsaco commented Jun 3, 2024

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

  1. Using quicktype as npm package dependency version 23.0.170
  2. Running an npm script with "quicktype -s schema test_schema.json -o schema.go" where test_schema.json has an external link (similar to the input data provided).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant