How to use the json-schema/lib/links.getLink function in json-schema

To help you get started, we’ve selected a few json-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github persvr / perstore / path.js View on Github external
function resolveLink(model, obj, linkId, getFunction, getDataModel){
    var id = (model.getId) ? model.getId(obj) : obj.id;
    id = ""+id;
    //console.log("resolving " + id + "/" + linkId);
    var value = obj;
    var linkTarget =  getLink(linkId, value, model);
    if(!linkTarget){
        value = value && value[linkId];
        linkTarget = (value!==undefined) && value.$ref;
    }
    if(linkTarget){
        if((linkTarget.charAt(0) == '/' || linkTarget.substring(0,3) == '../') && getDataModel){
            value = getFromDataModel(getDataModel(), linkTarget.substring(linkTarget.charAt(0) == '/' ? 1 : 3));
        }else{
            value = getFunction.call(self, linkTarget);
        }
    }
    return value;
    
}
github persvr / perstore / path.js View on Github external
//put the resolved sub-object into the object
                var id = (model.getId) ? model.getId(obj) : obj.id;
                var value =  resolveLink(model, obj, link.rel, originalGet, getDataModel);
                var promise = when(value, function(subObject){
                    if(subObject instanceof LazyArray){
                        //unpack the lazy array
                        promise = when(subObject.toRealArray(), function(arr){ obj[link.rel]=arr;});
                    }else{
                        obj[link.rel] = subObject;
                    }
                });
                return promise;
            }else if(link.resolution == "lazy"){
                //put a reference to the sub-object into the object
                var addLinkTask = new Promise();
                obj[link.rel] = {"$ref": getLink(link.rel, obj, model)};
                addLinkTask.callback();
                return addLinkTask;
            }
        });
        return when(all(promises), function(){return obj;});