Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
support schema inheritence for json schema so we can infer parent typ…
…e properties re #223
  • Loading branch information
jstrachan committed Apr 4, 2013
1 parent b195c6d commit b84a38e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/camel/js/helpers.ts
Expand Up @@ -65,7 +65,7 @@ module Camel {
* Looks up the given node name in the Camel schema
*/
export function getCamelSchema(nodeId) {
return nodeId ? _apacheCamelModel.definitions[nodeId] : null;
return Forms.lookupDefinition(nodeId, _apacheCamelModel);
}

/**
Expand Down
31 changes: 30 additions & 1 deletion hawtio-web/src/main/webapp/app/forms/js/helpers.ts
Expand Up @@ -23,7 +23,36 @@ module Forms {
if (schema) {
var defs = schema.definitions;
if (defs) {
return defs[name];
var answer = defs[name];
if (answer) {
var fullSchema = answer["fullSchema"];
if (fullSchema) {
return fullSchema;
}
// we may extend another, if so we need to copy in the base properties
var extendsTypes = Core.pathGet(answer, ["extends", "type"]);
if (extendsTypes) {
fullSchema = angular.copy(answer);
fullSchema.properties = fullSchema.properties || {};
if (!angular.isArray(extendsTypes)) {
extendsTypes = [extendsTypes];
}
angular.forEach(extendsTypes, (extendType) => {
if (angular.isString(extendType)) {
var extendDef = lookupDefinition(extendType, schema);
var properties = Core.pathGet(extendDef, ["properties"]);
if (properties) {
angular.forEach(properties, (property, key) => {
fullSchema.properties[key] = property;
});
}
}
});
answer["fullSchema"] = fullSchema;
return fullSchema;
}
}
return answer;
}
}
return null;
Expand Down
22 changes: 21 additions & 1 deletion hawtio-web/src/test/specs/spec/FormsSpec.js
Expand Up @@ -11,6 +11,15 @@ describe("Forms", function() {
"properties": {
"name": { "type": "string" },
"value": { "type": "string" }
}
},
"bar": {
"type": "object",
"extends": {
"type": "foo"
},
"properties": {
"cheese": { "type": "number" }
}
}
},
Expand Down Expand Up @@ -40,9 +49,10 @@ describe("Forms", function() {
};
var s1 = Forms.findArrayItemsSchema(schema.properties.tableValue, schema);
var s2 = Forms.findArrayItemsSchema(schema.properties.fooValue, schema);
var bar = Forms.lookupDefinition("bar", schema);

expect(Forms.resolveTypeNameAlias(null, schema)).toEqual(null);
expect(Forms.resolveTypeNameAlias("bar", schema)).toEqual("bar");
expect(Forms.resolveTypeNameAlias("something", schema)).toEqual("something");
expect(Forms.resolveTypeNameAlias("foo", schema)).toEqual("object");

expect(Forms.isArrayOrNestedObject(schema.properties.key, schema)).toEqual(false);
Expand All @@ -55,6 +65,16 @@ describe("Forms", function() {

expect(s1.properties.key.type).toEqual("string");
expect(s2.properties.name.type).toEqual("string");

expect(bar.properties.cheese.type).toEqual("number");
expect(bar.properties.name.type).toEqual("string");
expect(bar.properties.value.type).toEqual("string");
});

it("camel model has inheritence", function() {
var toSchema = Forms.lookupDefinition("to", _apacheCamelModel);

expect(toSchema.properties.id.type).toEqual("string");
});

it("properties lookup in json schema", function() {
Expand Down

0 comments on commit b84a38e

Please sign in to comment.