source: trip-planner-front/node_modules/json-schema-traverse/spec/fixtures/schema.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[6a3a178]1'use strict';
2
3var schema = {
4 additionalItems: subschema('additionalItems'),
5 items: subschema('items'),
6 contains: subschema('contains'),
7 additionalProperties: subschema('additionalProperties'),
8 propertyNames: subschema('propertyNames'),
9 not: subschema('not'),
10 allOf: [
11 subschema('allOf_0'),
12 subschema('allOf_1'),
13 {
14 items: [
15 subschema('items_0'),
16 subschema('items_1'),
17 ]
18 }
19 ],
20 anyOf: [
21 subschema('anyOf_0'),
22 subschema('anyOf_1'),
23 ],
24 oneOf: [
25 subschema('oneOf_0'),
26 subschema('oneOf_1'),
27 ],
28 definitions: {
29 foo: subschema('definitions_foo'),
30 bar: subschema('definitions_bar'),
31 },
32 properties: {
33 foo: subschema('properties_foo'),
34 bar: subschema('properties_bar'),
35 },
36 patternProperties: {
37 foo: subschema('patternProperties_foo'),
38 bar: subschema('patternProperties_bar'),
39 },
40 dependencies: {
41 foo: subschema('dependencies_foo'),
42 bar: subschema('dependencies_bar'),
43 },
44 required: ['foo', 'bar']
45};
46
47
48function subschema(keyword) {
49 var sch = {
50 properties: {},
51 additionalProperties: false,
52 additionalItems: false,
53 anyOf: [
54 {format: 'email'},
55 {format: 'hostname'}
56 ]
57 };
58 sch.properties['foo_' + keyword] = {title: 'foo'};
59 sch.properties['bar_' + keyword] = {title: 'bar'};
60 return sch;
61}
62
63
64module.exports = {
65 schema: schema,
66
67 // schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex
68 expectedCalls: [[schema, '', schema, undefined, undefined, undefined, undefined]]
69 .concat(expectedCalls('additionalItems'))
70 .concat(expectedCalls('items'))
71 .concat(expectedCalls('contains'))
72 .concat(expectedCalls('additionalProperties'))
73 .concat(expectedCalls('propertyNames'))
74 .concat(expectedCalls('not'))
75 .concat(expectedCallsChild('allOf', 0))
76 .concat(expectedCallsChild('allOf', 1))
77 .concat([
78 [schema.allOf[2], '/allOf/2', schema, '', 'allOf', schema, 2],
79 [schema.allOf[2].items[0], '/allOf/2/items/0', schema, '/allOf/2', 'items', schema.allOf[2], 0],
80 [schema.allOf[2].items[0].properties.foo_items_0, '/allOf/2/items/0/properties/foo_items_0', schema, '/allOf/2/items/0', 'properties', schema.allOf[2].items[0], 'foo_items_0'],
81 [schema.allOf[2].items[0].properties.bar_items_0, '/allOf/2/items/0/properties/bar_items_0', schema, '/allOf/2/items/0', 'properties', schema.allOf[2].items[0], 'bar_items_0'],
82 [schema.allOf[2].items[0].anyOf[0], '/allOf/2/items/0/anyOf/0', schema, '/allOf/2/items/0', 'anyOf', schema.allOf[2].items[0], 0],
83 [schema.allOf[2].items[0].anyOf[1], '/allOf/2/items/0/anyOf/1', schema, '/allOf/2/items/0', 'anyOf', schema.allOf[2].items[0], 1],
84
85 [schema.allOf[2].items[1], '/allOf/2/items/1', schema, '/allOf/2', 'items', schema.allOf[2], 1],
86 [schema.allOf[2].items[1].properties.foo_items_1, '/allOf/2/items/1/properties/foo_items_1', schema, '/allOf/2/items/1', 'properties', schema.allOf[2].items[1], 'foo_items_1'],
87 [schema.allOf[2].items[1].properties.bar_items_1, '/allOf/2/items/1/properties/bar_items_1', schema, '/allOf/2/items/1', 'properties', schema.allOf[2].items[1], 'bar_items_1'],
88 [schema.allOf[2].items[1].anyOf[0], '/allOf/2/items/1/anyOf/0', schema, '/allOf/2/items/1', 'anyOf', schema.allOf[2].items[1], 0],
89 [schema.allOf[2].items[1].anyOf[1], '/allOf/2/items/1/anyOf/1', schema, '/allOf/2/items/1', 'anyOf', schema.allOf[2].items[1], 1]
90 ])
91 .concat(expectedCallsChild('anyOf', 0))
92 .concat(expectedCallsChild('anyOf', 1))
93 .concat(expectedCallsChild('oneOf', 0))
94 .concat(expectedCallsChild('oneOf', 1))
95 .concat(expectedCallsChild('definitions', 'foo'))
96 .concat(expectedCallsChild('definitions', 'bar'))
97 .concat(expectedCallsChild('properties', 'foo'))
98 .concat(expectedCallsChild('properties', 'bar'))
99 .concat(expectedCallsChild('patternProperties', 'foo'))
100 .concat(expectedCallsChild('patternProperties', 'bar'))
101 .concat(expectedCallsChild('dependencies', 'foo'))
102 .concat(expectedCallsChild('dependencies', 'bar'))
103};
104
105
106function expectedCalls(keyword) {
107 return [
108 [schema[keyword], `/${keyword}`, schema, '', keyword, schema, undefined],
109 [schema[keyword].properties[`foo_${keyword}`], `/${keyword}/properties/foo_${keyword}`, schema, `/${keyword}`, 'properties', schema[keyword], `foo_${keyword}`],
110 [schema[keyword].properties[`bar_${keyword}`], `/${keyword}/properties/bar_${keyword}`, schema, `/${keyword}`, 'properties', schema[keyword], `bar_${keyword}`],
111 [schema[keyword].anyOf[0], `/${keyword}/anyOf/0`, schema, `/${keyword}`, 'anyOf', schema[keyword], 0],
112 [schema[keyword].anyOf[1], `/${keyword}/anyOf/1`, schema, `/${keyword}`, 'anyOf', schema[keyword], 1]
113 ];
114}
115
116
117function expectedCallsChild(keyword, i) {
118 return [
119 [schema[keyword][i], `/${keyword}/${i}`, schema, '', keyword, schema, i],
120 [schema[keyword][i].properties[`foo_${keyword}_${i}`], `/${keyword}/${i}/properties/foo_${keyword}_${i}`, schema, `/${keyword}/${i}`, 'properties', schema[keyword][i], `foo_${keyword}_${i}`],
121 [schema[keyword][i].properties[`bar_${keyword}_${i}`], `/${keyword}/${i}/properties/bar_${keyword}_${i}`, schema, `/${keyword}/${i}`, 'properties', schema[keyword][i], `bar_${keyword}_${i}`],
122 [schema[keyword][i].anyOf[0], `/${keyword}/${i}/anyOf/0`, schema, `/${keyword}/${i}`, 'anyOf', schema[keyword][i], 0],
123 [schema[keyword][i].anyOf[1], `/${keyword}/${i}/anyOf/1`, schema, `/${keyword}/${i}`, 'anyOf', schema[keyword][i], 1]
124 ];
125}
Note: See TracBrowser for help on using the repository browser.