CesiumGS / CesiumGS/wetzel

Definitions cannot refer to other definitions

Open
#73 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
137
Forks
52
PR merge metrics
No merged PRs in 30d

Description

Here is an example schema that refers to a type `exampleReferenceDefinition` that is defined in another file:

```
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title" : "Definitions user example",
"description" : "An example that uses definitions from another file",
"type" : "object",
"properties": {
"exampleProperty": {
"allOf": [
{
"$ref": "definitions.schema.json#/definitions/exampleReferenceDefinition"
}
]
}
}
}
```

The `definitions.schema.json` looks as follows:
```
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title" : "Definitions example",
"description" : "An example with definitions",
"type" : "object",
"definitions": {
"exampleDefinition": {
"title": "An example definition",
"type": "string"
},
"exampleReferenceDefinition": {
"title": "An example definition that refers to another one",
"allOf": [
{
"$ref": "#/definitions/exampleDefinition"
}
]
}
}
}
```

This causes wezel to bail out:
```
C:\wetzel\lib\replaceRef.js:54
throw new Error(`Unable to find $ref ${ref}`);
^

Error: Unable to find $ref #/definitions/exampleDefinition
at replaceRef (C:\wetzel\lib\replaceRef.js:54:19)
at replaceRef (C:\wetzel\lib\replaceRef.js:100:32)
...
```
Roughly: The `definitions` are not properly transported through the recursive calls of `replaceRef`.

My gut feeling is that this is related to https://github.com/CesiumGS/wetzel/issues/56 . More generally: The `replaceRef` approach of trying to completely "inline" the references may not be the most sustainable here. It does/will also cause trouble when/if [`allOf` is replaced with `$ref`](https://github.com/KhronosGroup/glTF/issues/2062).

I've spent a few hours debugging the surroundings of `replaceRef`. Maybe I'll try to refactor this in an attempt to kill a few bugs with one stone, but it's hard to make promises here...

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with lib/replaceRef.js and reproduce the failure using the two schemas in the issue, following the recursive call that raises “Unable to find $ref #/definitions/exampleDefinition.” Trace how definitions are passed through replaceRef and check the existing tests or entry points around reference replacement. Done means the external definition and its nested local reference resolve without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.