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

Definitions cannot refer to other definitions #73

Open
javagl opened this issue Apr 30, 2022 · 2 comments
Open

Definitions cannot refer to other definitions #73

javagl opened this issue Apr 30, 2022 · 2 comments

Comments

@javagl
Copy link
Contributor

javagl commented Apr 30, 2022

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 #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.

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...

@JC3
Copy link

JC3 commented Jun 30, 2022

This still appears to be an issue.

@javagl
Copy link
Contributor Author

javagl commented Jul 1, 2022

There haven't been any actual changes since this issue was reported. I tried to apply wetzel to another project, and stumbled over this and several other issues, and created a set of smaller changes to address them, but eventually, it did not appear to make sense to try and tackle these individually, so I created a branch with a larger refactoring at https://github.com/CesiumGS/wetzel/tree/generate-3dtiles (although I don't know for sure whether this really is an 'improvement', or just a 'change' ...)

I'll have a closer look at #81 and try to respond there a bit later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants