Commit c516bcd7 authored by Boris Kocherov's avatar Boris Kocherov

add guessing type of schema

parent 1901db39
......@@ -22,6 +22,48 @@
return typeof doc;
}
function guessSchemaType(schema) {
var property_name;
for (property_name in schema) {
if (schema.hasOwnProperty(property_name)) {
switch (property_name) {
// case "allOf":
// case "anyOf":
// case "oneOf":
// return false;
case "required":
case "maxProperties":
case "minProperties":
case "additionalProperties":
case "properties":
case "patternProperties":
case "dependencies":
case "propertyNames":
return "object";
case "additionalItems":
case "items":
case "maxItems":
case "minItems":
case "uniqueItems":
case "contains":
return "array";
case "maxLength":
case "minLength":
case "pattern":
case "contentEncoding":
case "contentMediaType":
return "string";
case "multipleOf":
case "maximum":
case "exclusiveMaximum":
case "minimum":
case "exclusiveMinimum":
return "number";
}
}
}
}
function createElement(type, props) {
var element = document.createElement(type),
key;
......@@ -1484,11 +1526,8 @@
options.delete_button = !options.required;
}
}
if (options.top && !options.type && !schema.type) {
// XXX use "object" as type for support buggy
// slapos schemas where some times type absent
// i need remove it in future
options.type = "object";
if (!options.type && schema && !schema.type) {
options.type = guessSchemaType(schema);
}
while (root.firstChild) {
root.removeChild(root.firstChild);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment