Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (promise) {
return promise
.then(function(data) {
// Update the $ref with the parsed file contents
var value = parse(data, $ref.path, options);
$ref.setValue(value, options);
return {
$ref: $ref,
cached: false
};
});
}
else {
return Promise.reject(ono.syntax('Unable to resolve $ref pointer "%s"', $ref.path));
}
}
catch (e) {
return Promise.reject(e);
}
}
}
catch (e) {
var ext = util.path.extname(path);
if (options.allow.unknown && ['.json', '.yaml', '.yml'].indexOf(ext) === -1) {
// It's not a YAML or JSON file, and unknown formats are allowed,
// so ignore the parsing error and just return the raw data
util.debug(' Unknown file format. Not parsed.');
parsed = data;
}
else {
throw ono.syntax(e, 'Error parsing "%s"', path);
}
}
if (isEmpty(parsed) && !options.allow.empty) {
throw ono.syntax('Error parsing "%s". \nParsed value is empty', path);
}
return parsed;
}
util.debug(' Parsed successfully');
}
else {
parsed = data;
}
}
catch (e) {
var ext = util.path.extname(path);
if (options.allow.unknown && ['.json', '.yaml', '.yml'].indexOf(ext) === -1) {
// It's not a YAML or JSON file, and unknown formats are allowed,
// so ignore the parsing error and just return the raw data
util.debug(' Unknown file format. Not parsed.');
parsed = data;
}
else {
throw ono.syntax(e, 'Error parsing "%s"', path);
}
}
if (isEmpty(parsed) && !options.allow.empty) {
throw ono.syntax('Error parsing "%s". \nParsed value is empty', path);
}
return parsed;
}
function onError(err) {
if (err) {
err = err instanceof Error ? err : new Error(err);
reject(ono.syntax(err, 'Error parsing %s', file.url));
}
else {
reject(ono.syntax('Unable to parse %s', file.url));
}
}
});
function onError(err) {
if (err && !(err instanceof SyntaxError)) {
reject(err);
}
reject(ono.syntax('Unable to resolve $ref pointer "%s"', path));
}
});
function setValue(pointer, token, value) {
if (pointer.value && typeof pointer.value === 'object') {
if (token === '-' && Array.isArray(pointer.value)) {
pointer.value.push(value);
}
else {
pointer.value[token] = value;
}
}
else {
throw ono.syntax('Error assigning $ref pointer "%s". \nCannot set "%s" of a non-object.', pointer.url, token);
}
return value;
}
function parseError (error, parseInfo) {
let { param, path } = parseInfo;
let message = `The "${param.name}" ${param.in} parameter is invalid.`;
if (path !== param.name) {
message += ` Error at ${path}.`;
}
return ono.syntax(error, { status: 400 }, message);
}
.then(function (result) {
if (!result || typeof result !== 'object' || Buffer.isBuffer(result)) {
throw ono.syntax('"%s" is not a valid JSON Schema', me.$refs._root$Ref.path || result);
}
else {
me.schema = result;
return maybe(args.callback, Promise.resolve(me.schema));
}
})
.catch(function (e) {
function returnTheSchema() {
if (!file.data || typeof file.data !== 'object' || Array.isArray(file.data)) {
reject(ono.syntax('"%s" is not a valid JSON Schema', url || file.data));
}
else {
resolve(schema);
}
}
});