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).
MIT License
223 stars 63 forks source link

Regression in 3.0.14 #176

Closed wickedest closed 4 years ago

wickedest commented 4 years ago

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: https://github.com/whitlockjc/json-refs/compare/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.

whitlockjc commented 4 years ago

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

whitlockjc commented 4 years ago

json-refs@3.0.15 has been released.

wickedest commented 4 years ago

tyvm!

whitlockjc commented 4 years ago

You got it!