Commit f2c8b82e authored by Boris Kocherov's avatar Boris Kocherov

add expandProperties()

parent 6d65e3c3
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
}); });
} }
expandSchema = function (g, schema, schema_path) { expandSchema = function (g, schema, schema_path, ref) {
if (schema === undefined) { if (schema === undefined) {
schema = true; schema = true;
} }
...@@ -279,18 +279,57 @@ ...@@ -279,18 +279,57 @@
if (schema.$ref) { if (schema.$ref) {
return g.loadJSONSchema(schema.$ref, schema_path) return g.loadJSONSchema(schema.$ref, schema_path)
.push(function (schema_part) { .push(function (schema_part) {
return expandSchema(g, schema_part, schema_path); return expandSchema(g, schema_part, schema_path, schema.$ref);
}); });
} }
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return [{ return [{
title: ref || schema.title,
schema: schema, schema: schema,
schema_path: schema_path schema_path: schema_path
}]; }];
}); });
}; };
function expandProperties(g, properties, schema_path) {
return RSVP.Queue()
.push(function () {
var property_name,
arr = [];
function addPropertyName(p_name) {
return function (schema_array) {
var i;
for (i = 0; i < schema_array.length; i += 1) {
// add propertyName to title
schema_array[i].title = p_name + ' / ' + schema_array[i].title;
// add propertyName to schemaItem
schema_array[i].property_name = property_name;
}
return schema_array;
};
}
for (property_name in properties) {
if (properties.hasOwnProperty(property_name)) {
arr.push(
expandSchema(g, properties[property_name], schema_path +
'/properties/' + encodeJsonPointer(property_name))
.push(addPropertyName(property_name))
);
}
}
return RSVP.all(arr);
})
.push(function (arr) {
var i,
schema_arr = [];
for (i = 0; i < arr.length; i += 1) {
schema_arr.concat(arr[i]);
}
return schema_arr;
});
}
function render_select_type(gadget, title, schema_arr, event) { function render_select_type(gadget, title, schema_arr, event) {
var scope = Math.random().toString(36).substr(2, 9), var scope = Math.random().toString(36).substr(2, 9),
type_arr = [], type_arr = [],
...@@ -313,7 +352,7 @@ ...@@ -313,7 +352,7 @@
} else { } else {
for (i = 0; i < schema_arr.length; i += 1) { for (i = 0; i < schema_arr.length; i += 1) {
schema_item = schema_arr[i]; schema_item = schema_arr[i];
description = schema_item.schema.$ref || schema_item.schema.title; description = schema_item.title;
if (getDocumentType(schema_item.schema.type) === "array") { if (getDocumentType(schema_item.schema.type) === "array") {
description = description || schema_item.schema.description; description = description || schema_item.schema.description;
for (z = 0; z < schema_item.schema.type.length; z += 1) { for (z = 0; z < schema_item.schema.type.length; z += 1) {
...@@ -322,6 +361,7 @@ ...@@ -322,6 +361,7 @@
title: description + ' # ' + type, title: description + ' # ' + type,
value: { value: {
type: type, type: type,
property_name: schema_item.property_name,
schema_path: schema_item.schema_path, schema_path: schema_item.schema_path,
schema: schema_item.schema schema: schema_item.schema
} }
...@@ -334,7 +374,7 @@ ...@@ -334,7 +374,7 @@
type_arr.push({ type_arr.push({
title: description, title: description,
value: { value: {
type: undefined, property_name: schema_item.property_name,
schema_path: schema_item.schema_path, schema_path: schema_item.schema_path,
schema: schema_item.schema schema: schema_item.schema
} }
......
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