Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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);
}
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();
});
});
}
app.get( '/api-docs', function ( req, res, next ) {
parser.bundle( 'test/petstore.yaml' ).then( function ( api ) {
res.json( api );
} ).catch( next );
} );
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}`);
});
}
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;
},
};
async function bundle (json) {
return RefParser.bundle(json, {
dereference: {
circular: 'ignore'
}
});
}
async function bundle (json) {
return RefParser.bundle(json, {
dereference: {
circular: 'ignore'
}
});
}