Skip to content

Commit

Permalink
Add support for the allOf keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Piela committed Nov 27, 2018
1 parent 44f27b2 commit b83bb78
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* @author Ignacio del Valle Alles [email protected]
*/

Expand Down Expand Up @@ -161,7 +161,7 @@ if (typeof brutusin === "undefined") {

renderers["string"] = function (container, id, parentObject, propertyProvider, value) {
/// TODO change the handler for when there is a 'media'
/// specifier so it becomes a file element.
/// specifier so it becomes a file element.
var schemaId = getSchemaId(id);
var parentId = getParentSchemaId(schemaId);
var s = getSchema(schemaId);
Expand Down Expand Up @@ -327,7 +327,7 @@ if (typeof brutusin === "undefined") {
// if (s.required) {
// input.required = true;
// }
//
//
// if (s.minimum) {
// input.min = s.minimum;
// }
Expand All @@ -349,7 +349,7 @@ if (typeof brutusin === "undefined") {
input = document.createElement("input");
input.type = "checkbox";
if (value === true || value !== false && s.default) {
input.checked = true;
input.checked = true;
}
} else {
input = document.createElement("select");
Expand Down Expand Up @@ -438,6 +438,23 @@ if (typeof brutusin === "undefined") {

};

renderers["allOf"] = function (container, id, parentObject, propertyProvider, value) {
var schemaId = getSchemaId(id);
var s = getSchema(schemaId);
for (var i = 0; i < s.allOf.length; i++) {
var propId = schemaId + "." + i;
var ss = getSchema(propId);
if (!ss.hasOwnProperty("type")) {
if (ss.hasOwnProperty("properties")) {
ss.type = "object";
}
}
var schemaDiv = document.createElement("div");
render(null, schemaDiv, id + "." + i, parentObject, propertyProvider, value);
appendChild(container, schemaDiv, ss);
}
};

renderers["object"] = function (container, id, parentObject, propertyProvider, value) {

function createStaticPropertyProvider(propname) {
Expand Down Expand Up @@ -978,6 +995,10 @@ if (typeof brutusin === "undefined") {
for (var i in schema.oneOf) {
renameRequiredPropeties(schema.oneOf[i]);
}
} else if (schema.hasOwnProperty("allOf")) {
for (i in schema.allOf) {
renameRequiredPropeties(schema.allOf[i]);
}
} else if (schema.hasOwnProperty("$ref")) {
var newSchema = getDefinition(schema["$ref"]);
renameRequiredPropeties(newSchema);
Expand All @@ -996,13 +1017,13 @@ if (typeof brutusin === "undefined") {
if (schema.patternProperties) {
for (var pat in schema.patternProperties) {
var s = schema.patternProperties[pat];
if (s.hasOwnProperty("type") || s.hasOwnProperty("$ref") || s.hasOwnProperty("oneOf")) {
if (s.hasOwnProperty("type") || s.hasOwnProperty("$ref") || s.hasOwnProperty("oneOf") || s.hasOwnProperty("allOf")) {
renameRequiredPropeties(schema.patternProperties[pat]);
}
}
}
if (schema.additionalProperties) {
if (schema.additionalProperties.hasOwnProperty("type") || schema.additionalProperties.hasOwnProperty("oneOf")) {
if (schema.additionalProperties.hasOwnProperty("type") || schema.additionalProperties.hasOwnProperty("oneOf") || schema.additionalProperties.hasOwnProperty("allOf")) {
renameRequiredPropeties(schema.additionalProperties);

}
Expand All @@ -1027,6 +1048,14 @@ if (typeof brutusin === "undefined") {
pseudoSchema.oneOf[i] = childProp;
populateSchemaMap(childProp, schema.oneOf[i]);
}
} else if (schema.hasOwnProperty("allOf")) {
pseudoSchema.allOf = new Array();
pseudoSchema.type = "allOf";
for (i in schema.allOf) {
childProp = name + "." + i;
pseudoSchema.allOf[i] = childProp;
populateSchemaMap(childProp, schema.allOf[i]);
}
} else if (schema.hasOwnProperty("$ref")) {
var refSchema = getDefinition(schema["$ref"]);
if (refSchema) {
Expand Down Expand Up @@ -1070,7 +1099,7 @@ if (typeof brutusin === "undefined") {
var s = schema.patternProperties[pat];

if (s.hasOwnProperty("type") || s.hasOwnProperty("$ref") ||
s.hasOwnProperty("oneOf")) {
s.hasOwnProperty("oneOf") || s.hasOwnProperty("allOf")) {
populateSchemaMap(patChildProp, schema.patternProperties[pat]);
} else {
populateSchemaMap(patChildProp, SCHEMA_ANY);
Expand All @@ -1081,7 +1110,8 @@ if (typeof brutusin === "undefined") {
var childProp = name + "[*]";
pseudoSchema.additionalProperties = childProp;
if (schema.additionalProperties.hasOwnProperty("type") ||
schema.additionalProperties.hasOwnProperty("oneOf")) {
schema.additionalProperties.hasOwnProperty("oneOf") ||
schema.additionalProperties.hasOwnProperty("allOf")) {
populateSchemaMap(childProp, schema.additionalProperties);
} else {
populateSchemaMap(childProp, SCHEMA_ANY);
Expand All @@ -1099,10 +1129,10 @@ if (typeof brutusin === "undefined") {
for (var i = 0; i < schema.dependsOn.length; i++) {
if (!schema.dependsOn[i]) {
arr[i] = "$";
// Relative cases
// Relative cases
} else if (schema.dependsOn[i].startsWith("$")) {
arr[i] = schema.dependsOn[i];
// Relative cases
// Relative cases
} else if (name.endsWith("]")) {
arr[i] = name + "." + schema.dependsOn[i];
} else {
Expand Down Expand Up @@ -1255,7 +1285,7 @@ if (typeof brutusin === "undefined") {
return input.getValue();
}
var value;

if (input.tagName.toLowerCase() === "select") {
value = input.options[input.selectedIndex].value;
} else {
Expand Down

0 comments on commit b83bb78

Please sign in to comment.