Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
taskEither.tryCatch(async () => {
const cwd = options.cwd || process.cwd();
const out = path.isAbsolute(options.out) ? options.out : path.resolve(cwd, options.out);
const spec = path.isAbsolute(options.spec) ? options.spec : path.resolve(cwd, options.spec);
log('Processing', spec);
const $refs = await $RefParser.resolve(spec, {
dereference: {
circular: 'ignore',
},
parse: {
sketch: sketchParser121,
},
});
const specs: Record = pipe(
Object.entries($refs.values()),
array.reduce({}, (acc, [fullPath, schema]) => {
const isRoot = fullPath === spec;
const relative = path.relative(cwd, fullPath);
// skip specLike check for root because it should always be decoded with passed decoder and fail
if (!isRoot && isLeft(specLikeCodec.decode(schema))) {
log('Unable to decode', relative, 'as spec. Treat it as an arbitrary json.');
wrapCommand(async (argv) => {
const { cwd, format, select, secrets } = argv;
const { config, nonSecrets } = await loadValidated(cwd);
const output = secrets ? config : nonSecrets;
const refs = await refParser.resolve(output);
console.log(stringify(refs.get(select) as any, extToFileType(format)));
}),
)
function(callback) {
process.chdir(path.dirname(spec));
RefParser.resolve(specInJson, function(err, result) {
process.chdir(cwd);
if (err) {
var msg = `Error occurred in resolving the spec "${spec}". Details of the error are:\n${util.format(err, {depth: null})}.`;
specValidationResult.resolveSpec = {};
specValidationResult.resolveSpec['RESOLVE_SPEC_ERROR'] = msg;
return callback(new Error(msg));
}
refSpecInJson = result;
return callback(null, refSpecInJson);
});
},
//Validate every scenario provided in every x-ms-examples extension for every operation.
leadingComments,
rendererOptions = {},
includeSecrets = false,
select = '#',
}) => {
let lines;
switch (type) {
case 'json':
case 'json5':
case 'toml':
case 'yml':
case 'yaml': {
const { config, nonSecrets } = await loadConfig(cwd);
const output = includeSecrets ? config : nonSecrets;
const refs = await refParser.resolve(output);
const selected = refs.get(select);
lines = [stringify(selected as ConfigObject, extToFileType(type))];
break;
}
default: {
lines = await generateQuicktype(
schema, schemaRefs, file, type, name, augmentModule, leadingComments, rendererOptions,
);
break;
}
}
await outputFile(join(cwd, file), `${lines.join('\n')}${'\n'}`);
}));