How to use the reftools/lib/findObj.js.findObj function in reftools

To help you get started, we’ve selected a few reftools 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 Mermade / oas-kit / packages / oas-overlay / index.js View on Github external
function process(result,src,update,options){
    for (let item of result) {
        const itype = truetype(item);
        if (options.verbose) {
            const present = findObj(src,item);
            console.warn('item',util.inspect({update:update,result:item,rtype:itype,locn:present},{depth:null,colors:true}));
        }
        if (itype === 'array') {
            if (update.concat) item = item.concat(update.concat);
            if (update.splice) item.splice.apply(update,update.splice);
            process(item,src,update,options);
        }
        else {
            if (typeof update.value !== 'undefined') {
                Object.assign(item,update.value);
            }
       }
    }
}
github Mermade / oas-kit / packages / oas-overlay / index.js View on Github external
function apply(overlay,openapi,options){
    const src = deref(clone(openapi));
    for (let update of overlay.updates||overlay.overlay.updates) {
        try {
            const result = jmespath.search(src,update.target);
            const rtype = truetype(result);
            const present = findObj(src,result);
            if (options.verbose) {
                console.warn('result',util.inspect({update:update,result:result,rtype:rtype,locn:present},{depth:Infinity,colors:true}));
            }
            if (rtype === 'object') {
                Object.assign(result,update.value);
            }
            else if (rtype === 'array') {
                if (present.found) {
                    if (Array.isArray(update.value)) {
                        for (let value of update.value) {
                            result.push(value);
                        }
                    }
                    else {
                        result.push(update.value);
                    }