whitlockjc / json-refs

Various utilities for JSON Pointers (http://tools.ietf.org/html/rfc6901) and JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression in 3.0.14

wickedest opened this issue · comments

Expected outcome
Using findRefs finds and returns a handle to the actual reference in the document.

Actual outcome
It returns a copy to that document.

Steps to reproduce

const assert = require('assert');
const jsonrefs = require('json-refs');
const defs = {
	$ref: '#/definitions/Pet'
};

const refs = jsonrefs.findRefs(defs, {
	filter: ref => ref.uri.startsWith('#/definitions/')
});

Object.keys(refs).forEach(refPath => {
	refs[refPath].def.$ref = 'EXAMPLE';
});

assert.equal(defs.$ref, 'EXAMPLE');

Using this tool, we were able to iterate over an existing JSON document and change the references. However, since 3.0.14, that is no longer possible. The issue appears to be the _.cloneDeep(obj) that was added as part of this commit:
v3.0.13...v3.0.14#diff-168726dbe96b3ce427e7fedce31bb0bcR680

As far as I can tell, there really is no need to clone the object. It does not appear to be modified within the function.

You are right, this was not intended. (I did this while testing and forgot to remove it.) I'll get a release out ASAP.

json-refs@3.0.15 has been released.

tyvm!

You got it!