How to use the json-schema-ref-parser.bundle function in json-schema-ref-parser

To help you get started, we’ve selected a few json-schema-ref-parser 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 cdimascio / express-openapi-validator / src / framework / index.ts View on Github external
// We need this workaround ( use '$RefParser.dereference' instead of '$RefParser.bundle' ) if asked by user
    if (typeof filePath === 'string') {
      const origCwd = process.cwd();
      const specDir = path.resolve(origCwd, path.dirname(filePath));
      const absolutePath = path.resolve(origCwd, filePath);
      if (fs.existsSync(absolutePath)) {
        // Get document, or throw exception on error
        try {
          process.chdir(specDir);
          const docWithRefs = jsYaml.safeLoad(
            fs.readFileSync(absolutePath, 'utf8'),
            { json: true },
          );
          return $refParser.mode === 'dereference'
            ? $RefParser.dereference(docWithRefs)
            : $RefParser.bundle(docWithRefs);
        } finally {
          process.chdir(origCwd);
        }
      } else {
        throw new Error(
          `${this.loggingPrefix}spec could not be read at ${filePath}`,
        );
      }
    }
    return $refParser.mode === 'dereference'
      ? $RefParser.dereference(filePath)
      : $RefParser.bundle(filePath);
  }
github Azure / azure-rest-api-specs / test / syntax.ts View on Github external
it(swagger + ' should be completely resolvable.', function (done) {
      RefParser.bundle(swagger, function (bundleErr: { readonly message: unknown }, _bundleResult: unknown) {
        if (bundleErr) {
          var msg = swagger + ' has references that cannot be resolved. They are as follows: \n' + util.inspect(bundleErr.message, { depth: null });
          console.log(msg);
          throw new Error(msg);
        }
        done();
      });
    });
  }
github mobilcom-debitel / got-swag / test / petstore.js View on Github external
app.get( '/api-docs', function ( req, res, next ) {
      parser.bundle( 'test/petstore.yaml' ).then( function ( api ) {
        res.json( api );
      } ).catch( next );
    } );
github cyclosproject / ng-swagger-gen / ng-swagger-gen.js View on Github external
function ngSwaggerGen(options) {
  if (typeof options.swagger != 'string') {
    console.error("Swagger file not specified in the 'swagger' option");
    process.exit(1);
  }

  setupProxy();
  
  $RefParser.bundle(options.swagger, { dereference: { circular: false } }).then(
    data => {
      doGenerate(data, options);
    },
    err => {
      console.error(
        `Error reading swagger location ${options.swagger}: ${err}`
      );
    }
  ).catch(function (error) {
    console.error(`Error: ${error}`);
  });
}
github cdimascio / express-openapi-validator / src / framework / json.ref.schema.ts View on Github external
bundle: (schema, options?) => {
    var savedError,
      savedResult,
      done = false;

    RefParser.bundle(schema, options, (error, result) => {
      savedError = error;
      savedResult = result;
      done = true;
    });

    loopWhile(() => !done);

    if (savedError) throw savedError;
    return savedResult;
  },
};
github openapi-contrib / openapi3-generator / lib / bundler.js View on Github external
async function bundle (json) {
  return RefParser.bundle(json, {
    dereference: {
      circular: 'ignore'
    }
  });
}
github asyncapi / generator / lib / parser.js View on Github external
async function bundle (json) {
  return RefParser.bundle(json, {
    dereference: {
      circular: 'ignore'
    }
  });
}