in tool/schemaHelper.js [30:112]
path ? (path + '.' + propName) : propName,
false
);
}
}
// Or it's a leaf node.
}
innerTraverse(schema.option, rootName, false);
};
module.exports.traverse = traverse;
function convertToTree(rootSchema, rootNode) {
function createNodeBase(schema) {
let schemaType = schema.type;
// Simplify type
if (schemaType instanceof Array && schemaType.length === 1) {
schemaType = schemaType[0];
}
let nodeBase = {};
// Get type from default if possible. Reduce size.
if (schema.default == null || typeof schema.default !== schemaType) {
nodeBase.type = schemaType;
}
if (schema.default != null) {
nodeBase.default = schema.default;
}
if (schema.items) { // Array also may has properties.
nodeBase.isArray = true;
}
else if (schema.properties && Object.keys(schema.properties).length) {
nodeBase.isObject = true;
}
return nodeBase;
}
function createArrayItemNode(schema, parentNode) {
let childNode = createNodeBase(schema, parentNode);
if (schema.properties && schema.properties.type && schema.properties.type.default) {
childNode.arrayItemType = schema.properties.type.default.replace(/'/g, '');
}
else {
console.error('schema', schema);
throw new Error('Some thing wrong happens');
}
return childNode;
}
function createPropertyNode(propName, schema, parentNode) {
let childNode = createNodeBase(schema, parentNode);
childNode.prop = propName;
return childNode;
}
function processObjectType(currentSchema, currentNode) {
if (!currentSchema.properties) {
return;
}
let children = [];
for (let propName in currentSchema.properties) {
let childSchema = currentSchema.properties[propName];
let childNode = createPropertyNode(propName, childSchema, currentNode);
processRecursively(childSchema, childNode);
children.push(childNode);
}
if (children.length) {
currentNode.children = children;
}
}
function processArrayType(currentSchema, currentNode) {
if (!currentSchema.items) {
return;
}
// Each item of array may have different type of object.
// Like series, visualMap, legend
if (currentSchema.items.anyOf) {
let children = [];
currentSchema.items.anyOf.forEach(itemSchema => {