Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const applySuppression = (result: SwaggerObject) => {
const rootInfo = getFilePosition(result)
// apply suppression
for (const s of suppressionArray) {
if (s.where !== undefined) {
const paths = it.flatMap(it.isArray(s.where) ? s.where : [s.where], where => {
try {
return jp.paths(result, where)
} catch (e) {
log.error(e)
// TODO: return the error.
return []
}
})
for (const p of paths) {
// drop "$" and apply suppressions.
setSuppression(getDescendantFilePosition(result, it.drop(p)), s)
}
} else {
setSuppression(rootInfo, s)
}
}
if (node.path) {
// in this case the path will be set to the url instead of the path to the property
if (node.code === "INVALID_REQUEST_PARAMETER" && node.in === "body") {
node.path = []
} else if (
(node.in === "query" || node.in === "path") &&
node.path[0] === "paths" &&
node.name
) {
// in this case we will want to normalize the path with the uri and the paramter name
node.path = [node.path[1], node.name]
}
path = consolidatePath(path, node.path)
}
const serializedErrors = flatMap(node.errors, validationError =>
serializeErrors(validationError, path)
).toArray()
const serializedInner = fold(
node.inner,
(acc, validationError) => {
const errs = serializeErrors(validationError, path)
errs.forEach(err => {
const similarErr = acc.find(el => areErrorsSimilar(err, el))
if (similarErr && similarErr.path) {
if (!similarErr.similarPaths) {
similarErr.similarPaths = []
}
similarErr.similarPaths.push(err.path as string)
if (!similarErr.similarJsonPaths) {
export const splitPathAndReverse = (p: string | undefined) =>
p === undefined ? undefined : Array.from(flatMap(p.split("/"), s => s.split("\\"))).reverse()