glideapps / glideapps/quicktype
Implement $id and $ref properly
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
The current situation is a mess, and probably quite buggy. We have two separate schema crawlers - one in the canonizer, the other one in the type-building parser. We mix canonical refs and virtual refs too much.
Here's what I think a proper implementation should do:
* Have one type for traversing schema objects. It has to combine the schema object with its location, which can be any number of refs, I think. See the [relevant section in the JSON Schema spec](http://json-schema.org/latest/json-schema-core.html#rfc.section.8.2.4). The only way to traverse a schema is to use that type.
* Whenever a new schema file is loaded every single one of its refs is registered by the canonizer, so that no traversing is necessary to look up a `$ref`.
* When a `$ref` is resolved, the canonizer's map is consulted first. If the ref isn't registered, candidates for its address have to be attempted to fetch. There might be more than one, since a ref to `foo.schema` could mean `foo.schema` in the current directory, or relative to the where the referencing schema is. Alternative opinion: it can't mean the current directory, because then it would be dependent on where quicktype is called from. So either we've registered `foo.schema` before, via some `$id`, or we interpret it relative to the referencing schema.
The whole point of this is to decouple everything that's going on, and to have only one, clear place where policy is decided.
Contributor guide
Assessment
This issue has not been assessed yet.