Have you explored the capabilities of the djvi library for your needs?
The demonstration provided includes:
var jsonSchema = {"common":{"properties":{"type":{"enum":["common"]}},"required":["type"]}};
var env = new djvi();
env.addSchema('test', jsonSchema);
env.instance('test#/common');
// => { type: 'common' }
This could potentially be the solution you are seeking.
If this specific solution is not what you're looking for, I encountered a similar issue and devised a different approach to generate a parent object as a function. It might offer some assistance:
var dbdict = {
"title": "Entity",
"description": "An entity",
"type":"object",
"properties": {
"geometries": {"type": "array",
"items": {
"$ref" : "geometry"
}
}
}
}
var walkJSONSchema = function (JSONSchema, returnFunction) {
var walkObject = function(PROPS) {
var $this = this,
$child = {}
;
if(returnFunction == true) {
$child = new function() {};
}
//console.log("PROPS");
//console.log(PROPS);
for(var key in PROPS) {
console.log("key:"+key+" type:"+PROPS[key].type+" default:"+PROPS[key].default);
switch(PROPS[key].type) {
case "boolean":
$child[key] = PROPS[key].default || undefined;
break;
case "integer":
case "number":
$child[key] = PROPS[key].default || undefined;
break;
case "array":
$child[key] = [].push($this.walkObject(PROPS[key].properties));
break;
case "object":
$child[key] = $this.walkObject(PROPS[key].properties);
break;
case "string":
$child[key] = PROPS[key].default || undefined;
break;
};
};
return $child;
}
return walkObject(JSONSchema.properties);
}
Entity = walkJSONSchema(dbdict, true);
You have the flexibility to customize how you access the "Entity" from the schema document using your preferred scripting method, but this provides a functional option.