Skip to content

Commit 5842cc3

Browse files
committed
feat: deep-clone source schema defined with $ref, closes #4
1 parent 8fe8390 commit 5842cc3

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

keywords/add_keyword.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
var url = require('url');
44

5-
function copy(o, to) {
6-
to = to || {};
7-
for (var key in o) to[key] = o[key];
8-
return to;
9-
}
10-
115
module.exports = function (ajv, keyword, jsonPatch, patchSchema) {
126
if (!ajv._opts.v5)
137
throw new Error('keyword ' + keyword + ' requires v5 option');
148
ajv.addKeyword(keyword, {
159
macro: function (schema, parentSchema, it) {
1610
var source = schema.source;
1711
var patch = schema.with;
18-
if (source.$ref) source = copy(getSchema(source.$ref));
12+
if (source.$ref) source = JSON.parse(JSON.stringify(getSchema(source.$ref)));
1913
if (patch.$ref) patch = getSchema(patch.$ref);
2014
jsonPatch.apply(source, patch, true);
2115
return source;

0 commit comments

Comments
 (0)