CesiumGS / CesiumGS/wetzel

Handle circular refs in schema

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

Description

I use a circular model for my JSON schema. So as an example JSON, something like this:

```json
{
"guides": [{
// This can go on forever recursively
"children": [{
"children": [{
"name": "My Item"
}]
}]
}]
}
```

Here is JSON schema
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"DocsConfigNavigation": {
"anyOf": [
{
"$ref": "#/definitions/DocsConfigNavigationPage"
},
{
"$ref": "#/definitions/DocsConfigNavigationCategory"
}
]
},
"DocsConfigNavigationCategory": {
"properties": {
"children": {
"items": {
"$ref": "#/definitions/DocsConfigNavigation"
},
"type": "array"
}
},
"required": [
"children"
],
"type": "object"
},
"DocsConfigNavigationPage": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
}
},
"properties": {
"guides": {
"items": {
"$ref": "#/definitions/DocsConfigNavigation"
},
"type": "array"
}
},
"type": "object"
}

```

This results in the following error:

```
$ wetzel docs.schema.json
/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/defaultValue.js:14
function defaultValue(value, fallback) {
^

RangeError: Maximum call stack size exceeded
at defaultValue (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/defaultValue.js:14:22)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:28:24)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:90:16)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:90:16)
at replaceRef (/Users/brunnel6/.npm-packages/lib/node_modules/wetzel/lib/replaceRef.js:96:32)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the circular schema from the issue, then inspect lib/replaceRef.js and lib/defaultValue.js, where the stack trace points. Check how the wetzel command processes the schema and determine the expected handling and output for circular references, since the issue does not specify it. Done should include a verified run that no longer overflows the call stack.

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.