How to use the reftools/lib/recurse.recurse 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 APIs-guru / asyncapi-directory / index.js View on Github external
function fixApi(api) {
    if (api.version && !api.asyncapi) {
        api.asyncapi = api.version;
        delete api.version;
    }
    if (api.info.version === '1.2.0') api.info.version = '1.0.0';
    recurse(api,{},function(obj,key,state){
        if (key === 'asyncapi_servers_variables') {
            obj.variables = obj[key];
            delete obj[key];
        }
        else if (key === '$ref') {
            if (obj[key].startsWith('#/components/')) {
                const found = jptr(api,obj[key]);
                if (found === false) {
                    console.warn('Not found',obj[key]);
                    delete obj.$ref;
                }
            }
        }
    });
    return api;
}
github Mermade / check_api / index.js View on Github external
}
    else if (api && api.openapi) {
    console.warn('Unknown openapi version: '+api.openapi);
    }
    else if (api && api.asyncapi && (typeof api.asyncapi === 'string') && api.asyncapi.startsWith('1.')) {
        options.format = 'asyncapi_1';
    }
    else if (api && api.asyncapi) {
    console.warn('Unknown asyncapi version: '+api.asyncapi);
    }
    else if (api && api.version) {
        console.warn('Kin!');
        options.format = 'asyncapi_1';
        api.asyncapi = api.version;
        delete api.version;
        recurse(api,{},function(obj,key,state){
            if (key === 'asyncapi_servers_variables') {
                obj.variables = obj.asyncapi_servers_variables;
                delete obj.asyncapi_servers_variables;
            }
        });
    }
}

if (options.format === 'openapi_3') {
    var options = {laxRefs:true,resolve:true,source:options.source,convert:options.convert};
    try {
        openapi3.validate(api, options, function(err, opts) {
            if (err) {
                return callback(err, err.options||opts||options);
            }
            options.converted = options.openapi||api;