How to use the @stoplight/json.pointerToPath function in @stoplight/json

To help you get started, we’ve selected a few @stoplight/json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / spectral / src / resolved.ts View on Github external
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;
  }
github stoplightio / prism / packages / http / src / utils / runtimeExpression.ts View on Github external
          O.chain(part => O.tryCatch(() => pointerToPath('#' + part))),
          O.chain(path => O.fromNullable(_get(body, path)))
github stoplightio / spectral / src / utils / refs.ts View on Github external
export const safePointerToPath = (pointer: string): JsonPath => {
  const rawPointer = extractPointerFromRef(pointer);
  return rawPointer ? pointerToPath(rawPointer) : [];
};