@@ -48,33 +48,45 @@ test('ref internal - properties', (t) => {
48
48
test ( 'ref external - properties' , ( t ) => {
49
49
t . plan ( 2 )
50
50
51
- const schema = {
52
- title : 'object with $ref' ,
53
- definitions : {
54
- def : {
55
- type : 'object' ,
56
- properties : {
57
- str : {
58
- type : 'string'
51
+ const externalSchema = {
52
+ first : require ( './ref.json' ) ,
53
+ second : {
54
+ definitions : {
55
+ num : {
56
+ type : 'object' ,
57
+ properties : {
58
+ int : {
59
+ type : 'integer'
60
+ }
59
61
}
60
62
}
61
63
}
62
- } ,
64
+ }
65
+ }
66
+
67
+ const schema = {
68
+ title : 'object with $ref' ,
63
69
type : 'object' ,
64
70
properties : {
65
71
obj : {
66
- $ref : __dirname + '/ref.json#/definitions/def' // eslint-disable-line
72
+ $ref : 'first#/definitions/def'
73
+ } ,
74
+ num : {
75
+ $ref : 'second#/definitions/num'
67
76
}
68
77
}
69
78
}
70
79
71
80
const object = {
72
81
obj : {
73
82
str : 'test'
83
+ } ,
84
+ num : {
85
+ int : 42
74
86
}
75
87
}
76
88
77
- const stringify = build ( schema )
89
+ const stringify = build ( schema , { schema : externalSchema } )
78
90
const output = stringify ( object )
79
91
80
92
try {
@@ -84,7 +96,7 @@ test('ref external - properties', (t) => {
84
96
t . fail ( )
85
97
}
86
98
87
- t . equal ( '{"obj":{"str":"test"}}' , output )
99
+ t . equal ( '{"obj":{"str":"test"},"num":{"int":42} }' , output )
88
100
} )
89
101
90
102
test ( 'ref internal - patternProperties' , ( t ) => {
@@ -219,3 +231,58 @@ test('ref internal - pattern-additional Properties', (t) => {
219
231
220
232
t . equal ( '{"reg":{"str":"test"},"obj":{"str":"test"}}' , output )
221
233
} )
234
+
235
+ test ( 'ref external - pattern-additional Properties' , ( t ) => {
236
+ t . plan ( 2 )
237
+
238
+ const externalSchema = {
239
+ first : require ( './ref.json' ) ,
240
+ second : {
241
+ definitions : {
242
+ num : {
243
+ type : 'object' ,
244
+ properties : {
245
+ int : {
246
+ type : 'integer'
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+
254
+ const schema = {
255
+ title : 'object with $ref' ,
256
+ type : 'object' ,
257
+ properties : { } ,
258
+ patternProperties : {
259
+ reg : {
260
+ $ref : 'first#/definitions/def'
261
+ }
262
+ } ,
263
+ additionalProperties : {
264
+ $ref : 'second#/definitions/num'
265
+ }
266
+ }
267
+
268
+ const object = {
269
+ reg : {
270
+ str : 'test'
271
+ } ,
272
+ obj : {
273
+ int : 42
274
+ }
275
+ }
276
+
277
+ const stringify = build ( schema , { schema : externalSchema } )
278
+ const output = stringify ( object )
279
+
280
+ try {
281
+ JSON . parse ( output )
282
+ t . pass ( )
283
+ } catch ( e ) {
284
+ t . fail ( )
285
+ }
286
+
287
+ t . equal ( '{"reg":{"str":"test"},"obj":{"int":42}}' , output )
288
+ } )
0 commit comments