Skip to content

Commit

Permalink
feat: deep-clone source schema defined with $ref, closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Aug 30, 2016
1 parent 8fe8390 commit 5842cc3
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions keywords/add_keyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

var url = require('url');

function copy(o, to) {
to = to || {};
for (var key in o) to[key] = o[key];
return to;
}

module.exports = function (ajv, keyword, jsonPatch, patchSchema) {
if (!ajv._opts.v5)
throw new Error('keyword ' + keyword + ' requires v5 option');
ajv.addKeyword(keyword, {
macro: function (schema, parentSchema, it) {
var source = schema.source;
var patch = schema.with;
if (source.$ref) source = copy(getSchema(source.$ref));
if (source.$ref) source = JSON.parse(JSON.stringify(getSchema(source.$ref)));
if (patch.$ref) patch = getSchema(patch.$ref);
jsonPatch.apply(source, patch, true);
return source;
Expand Down

0 comments on commit 5842cc3

Please sign in to comment.