UNPKG

2.25 kBJavaScriptView Raw
1'use strict';
2
3var Ajv = require('ajv');
4var addKeywords = require('..');
5var addPatch = require('../keywords/patch');
6var test = require('./test_validate');
7
8describe('keyword $patch', function() {
9 var ajvInstances;
10
11 beforeEach(function() {
12 ajvInstances = [ new Ajv, new Ajv ];
13 addKeywords(ajvInstances[0]);
14 addPatch(ajvInstances[1]);
15 });
16
17 it('should extend schema defined in $patch', function() {
18 ajvInstances.forEach(testPatch);
19
20 function testPatch(ajv) {
21 var schema = {
22 "$patch": {
23 "source": {
24 "type": "object",
25 "properties": { "p": { "type": "string" } },
26 "additionalProperties": false
27 },
28 "with": [
29 { "op": "add", "path": "/properties/q", "value": { "type": "number" } }
30 ]
31 }
32 };
33
34 var validate = ajv.compile(schema);
35 test(validate, '$patch');
36 }
37 });
38
39 it('should extend schema defined in $ref', function() {
40 ajvInstances.forEach(testPatch);
41
42 function testPatch(ajv) {
43 var sourceSchema = {
44 "$id": "obj.json#",
45 "type": "object",
46 "properties": { "p": { "type": "string" } },
47 "additionalProperties": false
48 };
49
50 ajv.addSchema(sourceSchema);
51
52 var schema = {
53 "$patch": {
54 "source": { "$ref": "obj.json#" },
55 "with": [
56 { "op": "add", "path": "/properties/q", "value": { "type": "number" } }
57 ]
58 }
59 };
60
61 var validate = ajv.compile(schema);
62 test(validate, '$patch');
63 }
64 });
65
66 it('should extend schema defined with relative $ref', function() {
67 ajvInstances.forEach(testPatch);
68
69 function testPatch(ajv) {
70 var schema = {
71 "$id": "obj.json#",
72 "definitions": {
73 "source": {
74 "type": "object",
75 "properties": { "p": { "type": "string" } },
76 "additionalProperties": false
77 }
78 },
79 "$patch": {
80 "source": { "$ref": "#/definitions/source" },
81 "with": [
82 { "op": "add", "path": "/properties/q", "value": { "type": "number" } }
83 ]
84 }
85 };
86
87 var validate = ajv.compile(schema);
88 test(validate, '$patch');
89 }
90 });
91});