Commit 73ed449e authored by Boris Kocherov's avatar Boris Kocherov

begin allOf support

parent 15ad8951
...@@ -244,6 +244,51 @@ ...@@ -244,6 +244,51 @@
return queue; return queue;
} }
function expandSchema(g, schema, schema_path) {
if (schema.$ref) {
return g.loadJSONSchema(schema.$ref, schema_path)
.push(function (schema_part) {
return schema_part;
});
}
return RSVP.Queue()
.push(function () {
return schema;
});
}
function allOf(g, schema_array, schema_path) {
return RSVP.Queue()
.push(function () {
var i,
arr = [];
for (i = 0; i < schema_array.length; i += 1) {
arr.push(expandSchema(g, schema_array[i], schema_path));
}
return RSVP.all(arr);
})
.push(function (arr) {
var i,
key,
next_schema,
schema = arr[0];
for (i = 1; i < arr.length; i += 1) {
next_schema = arr[i];
for (key in next_schema) {
if (next_schema.hasOwnProperty(key)) {
if (schema.hasOwnProperty(key)) {
// XXX need use many many rules for merging
schema[key] = next_schema[key];
} else {
schema[key] = next_schema[key];
}
}
}
}
return schema;
});
}
function render_field(gadget, key, path, json_field, default_value, root, schema_path) { function render_field(gadget, key, path, json_field, default_value, root, schema_path) {
var div, var div,
label, label,
...@@ -264,6 +309,13 @@ ...@@ -264,6 +309,13 @@
json_field = getDocumentSchema(default_value); json_field = getDocumentSchema(default_value);
} }
if (json_field.allOf !== undefined) {
return allOf(gadget, json_field.allOf, schema_path)
.push(function (schema_part) {
return render_field(gadget, key, path, schema_part, default_value, root, schema_path);
});
}
if (json_field.$ref !== undefined) { if (json_field.$ref !== undefined) {
return gadget.loadJSONSchema(json_field.$ref, schema_path) return gadget.loadJSONSchema(json_field.$ref, schema_path)
.push(function (schema_part) { .push(function (schema_part) {
......
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