How to use the json-refs.clearCache function in json-refs

To help you get started, we’ve selected a few json-refs 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 moon0326 / swagger-ui-watcher / index.js View on Github external
function bundle(swaggerFile) {
  var root = yaml.safeLoad(fs.readFileSync(swaggerFile, 'utf8'));
  var options = {
    filter : ['relative', 'remote'],
    resolveCirculars: true,
    location: swaggerFile,
    loaderOptions : {
      processContent : function (res, callback) {
        callback(undefined, yaml.safeLoad(res.text));
      }
    }
  };
  JsonRefs.clearCache();
  return JsonRefs.resolveRefs(root, options).then(function (results) {
    var resErrors = {};
    for (const [k,v] of Object.entries(results.refs)) {
      if ('missing' in v && v.missing === true && (v.type == 'relative' || v.type === 'remote'))
        resErrors[k] = v.error;
    }

    if (Object.keys(resErrors).length > 0) {
      return Promise.reject(dictToString(resErrors));
    }

    return results.resolved;
  }, function (e) {
      var error = {};
      Object.getOwnPropertyNames(e).forEach(function (key) {
        error[key] = e[key];
github philosowaffle / vs-openapi-designer / extension.js View on Github external
function bundle(swaggerFile) {
    var root = yaml.safeLoad(fs.readFileSync(swaggerFile, 'utf8'));
    var options = {
        filter : ['relative', 'remote'],
        resolveCirculars: true,
        location: swaggerFile,
        loaderOptions : {
        processContent : function (res, callback) {
            callback(undefined, yaml.safeLoad(res.text));
        }
        }
    };
    JsonRefs.clearCache();
    return JsonRefs.resolveRefs(root, options).then(function (results) {
        var resErrors = {};
        for (const [k,v] of Object.entries(results.refs)) {
        if ('missing' in v && v.missing === true)
            resErrors[k] = v.error;
        }

        if (Object.keys(resErrors).length > 0) {
        return Promise.reject(dictToString(resErrors));
        }

        return results.resolved;
    }, function (e) {
        var error = {};
        Object.getOwnPropertyNames(e).forEach(function (key) {
            error[key] = e[key];

json-refs

Various utilities for JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis