Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applyPatch() validator index is not incrementing #300

Open
beam-bence opened this issue Sep 8, 2022 · 0 comments
Open

applyPatch() validator index is not incrementing #300

beam-bence opened this issue Sep 8, 2022 · 0 comments

Comments

@beam-bence
Copy link

beam-bence commented Sep 8, 2022

Using applyPatch, the index parameter of the custom validator function stays 0 with every call:

       applyPatch(
          json,
          operations,
          (change, index, tree, existingPath) => {
            const parentPath = change.path
              .split('/')
              .slice(0, change.path.split('/').length - 1)
              .join('/');
            if (!jsonpointer.exists(tree, parentPath)) {
              const extendedTree = {...tree};
              jsonpointer.set(extendedTree, parentPath, {});
              const fixChanges = compare(tree, extendedTree);

              //TODO fix bug index is always 0
              fixedChanges.splice(index, 0, ...fixChanges);
              throw new JsonPatchError(
                'Cannot perform operation at the desired path',
                'OPERATION_PATH_UNRESOLVABLE',
                index,
                change,
                tree
              );
            }
          },
          false //mutateDocument
        ).newDocument;

In the source, constant zero is passed instead of index:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant