glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.39k stars 1.08k forks source link

Allow `true` as a schema in `"items":true` #2411

Closed feefladder closed 8 months ago

feefladder commented 1 year ago

slack discussion: https://json-schema.slack.com/archives/CT8QRGTK5/p1671466458144969?thread_ts=1671397459.161829&cid=CT8QRGTK5 Issue: radiantearth/stac-spec#1246 Basically, true is considered a schema, that just passes everything in validation (slack). However, when trying to create a schema for JSON schema itself:

uicktype --src https://json-schema.org/draft/2020-12/schema --src-lang schema -l typescript --just-types -o schema.d.ts --debug all

This errors out, because enum is an array of any type, e.g.

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "properties": {
        "enum": {
            "type": "array",
            "items": true
        }
   }
}

gives

resolving # relative to schema.json# (schema.json#)
trying to fetch schema.json
successully fetched schema.json
resolved to # (schema.json#)
resolving # relative to schema.json# (schema.json#)
resolved to # (schema.json#)
Error: Array items must be an array or an object, but is true.