Skip to content

Commit

Permalink
Merge pull request #1542 from DCkQ6/ISSUE-1541-default-null-in-reference
Browse files Browse the repository at this point in the history
ISSUE-1541 default null in reference
  • Loading branch information
schmunk42 committed Apr 15, 2024
2 parents 5a8c22d + 431fa39 commit d0ddff9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/schemaloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class SchemaLoader {
*/
_manageRecursivePointer (schema, path) {
Object.keys(schema).forEach(i => {
if (schema[i].$ref && schema[i].$ref.indexOf('#') === 0) {
if (schema[i] !== null && schema[i].$ref && schema[i].$ref.indexOf('#') === 0) {
schema[i].$ref = path + schema[i].$ref
}
})
Expand Down
8 changes: 8 additions & 0 deletions tests/codeceptjs/issues/issue-gh-1541_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* /* global Feature Scenario */

Feature('issues')

Scenario('GitHub issue 1541 should remain fixed @issue-1541 ', async ({ I }) => {
I.amOnPage('issues/issue-gh-1541.html')
I.waitForElement('.je-ready')
})
51 changes: 51 additions & 0 deletions tests/pages/issues/issue-gh-1541.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>dependentRequired</title>
<script src="../../../dist/jsoneditor.js"></script>
<link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
</head>
<body>

<div class="container">
<h1>Test</h1>
<div id='editor-container'></div>

<div class="form-group">
<label for="textarea-value">Value</label>
<textarea class="form-control" id="textarea-value" cols="30" rows="10"></textarea>
</div>
</div>

<script>
var editorContainer = document.querySelector('#editor-container')
var textareaValue = document.querySelector('#textarea-value')
var schema = {
'title': 'Dependency chain support',
'type': 'object',
'properties': {
"reference": {
"title": "Reference",
"$ref": "issue-gh-1541.json"
}
}
}

var editor = new JSONEditor(editorContainer, {
schema: schema,
theme: 'bootstrap4',
iconlib: 'fontawesome',
show_errors: 'always',
show_opt_in: false,
ajax: true,
})

editor.on('change', function () {
textareaValue.value = JSON.stringify(editor.getValue())
})
</script>

</body>
</html>`
9 changes: 9 additions & 0 deletions tests/pages/issues/issue-gh-1541.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "external-schema",
"properties": {
"value": {
"type": ["string", "null"],
"default": null
}
}
}

0 comments on commit d0ddff9

Please sign in to comment.