Use JSON schema title as name for the root object if defined (see #635)

This commit is contained in:
jos 2019-06-12 15:43:16 +02:00
parent 4813cd79a1
commit 10daf40b56
4 changed files with 16 additions and 7 deletions

View File

@ -8,6 +8,7 @@ https://github.com/josdejong/jsoneditor
- Breaking change: upgraded dependency `ajv@6.10.0`, supporting JSON schema
draft-07 alongside draft-06 and draft-04.
- Upgraded dependency `vanilla-picker@2.8.1`.
- Use JSON schema title as name for the root object if defined (see #635).
## 2019-06-08, version 5.34.0

View File

@ -35,7 +35,8 @@
<script>
var schema = {
"title": "Example Schema",
"title": "Employee",
"description": "Object containing employee details",
"type": "object",
"properties": {
"firstName": {

View File

@ -2483,7 +2483,7 @@ Node.prototype.updateField = function (field) {
* indexes of the node will be updated too. False by
* default.
*/
Node.prototype.updateDom = function (options) {
Node.prototype.updateDom = function(options) {
// update level indentation
var domTree = this.dom.tree;
if (domTree) {
@ -2512,12 +2512,19 @@ Node.prototype.updateDom = function (options) {
else if (this.field != undefined) {
fieldText = this.field;
}
else {
var schema = Node._findSchema(this.editor.options.schema,this.editor.options.schemaRefs || {}, this.getPath());
if (schema && schema.title) {
fieldText = schema.title;
}
else if (this._hasChilds()) {
fieldText = this.type;
}
else {
fieldText = '';
}
}
domField.innerHTML = this._escapeHTML(fieldText);
this._updateSchema();

View File

@ -39,7 +39,7 @@
var container = document.getElementById('jsoneditor');
var schema = {
"title": "Example Schema",
"title": "User",
"type": "object",
"properties": {
"firstName": {