Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public doesBelongToDoc(path: JsonPath): boolean {
if (path.length === 0) {
// todo: each rule and their function should be context-aware, meaning they should aware of the fact they operate on resolved content
// let's assume the error was reported correctly by any custom rule /shrug
return true;
}
let piece = this.unresolved;
for (let i = 0; i < path.length; i++) {
if (!isObject(piece)) return false;
if (path[i] in piece) {
piece = piece[path[i]];
} else if (hasRef(piece)) {
return this.doesBelongToDoc([...pointerToPath(piece.$ref), ...path.slice(i)]);
}
}
return true;
}
O.chain(part => O.tryCatch(() => pointerToPath('#' + part))),
O.chain(path => O.fromNullable(_get(body, path)))
export const safePointerToPath = (pointer: string): JsonPath => {
const rawPointer = extractPointerFromRef(pointer);
return rawPointer ? pointerToPath(rawPointer) : [];
};