File tree Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,42 @@ test('ref internal - properties', (t) => {
4545 t . equal ( '{"obj":{"str":"test"}}' , output )
4646} )
4747
48+ test ( 'ref internal - items' , ( t ) => {
49+ t . plan ( 2 )
50+
51+ const schema = {
52+ title : 'array with $ref' ,
53+ definitions : {
54+ def : {
55+ type : 'object' ,
56+ properties : {
57+ str : {
58+ type : 'string'
59+ }
60+ }
61+ }
62+ } ,
63+ type : 'array' ,
64+ items : { $ref : '#/definitions/def' }
65+ }
66+
67+ const array = [ {
68+ str : 'test'
69+ } ]
70+
71+ const stringify = build ( schema )
72+ const output = stringify ( array )
73+
74+ try {
75+ JSON . parse ( output )
76+ t . pass ( )
77+ } catch ( e ) {
78+ t . fail ( )
79+ }
80+
81+ t . equal ( '[{"str":"test"}]' , output )
82+ } )
83+
4884test ( 'ref external - properties' , ( t ) => {
4985 t . plan ( 2 )
5086
@@ -286,3 +322,59 @@ test('ref external - pattern-additional Properties', (t) => {
286322
287323 t . equal ( '{"reg":{"str":"test"},"obj":{"int":42}}' , output )
288324} )
325+
326+ test ( 'ref internal - deepObject schema' , ( t ) => {
327+ t . plan ( 2 )
328+
329+ const schema = {
330+ title : 'object with $ref' ,
331+ definitions : {
332+ def : {
333+ type : 'object' ,
334+ properties : {
335+ coming : {
336+ type : 'object' ,
337+ properties : {
338+ where : {
339+ type : 'string'
340+ }
341+ }
342+ }
343+ }
344+ }
345+ } ,
346+ type : 'object' ,
347+ properties : {
348+ winter : {
349+ type : 'object' ,
350+ properties : {
351+ is : {
352+ $ref : '#/definitions/def'
353+ }
354+ }
355+ }
356+ }
357+ }
358+
359+ const object = {
360+ winter : {
361+ is : {
362+ coming : {
363+ where : 'to town'
364+ }
365+ }
366+ }
367+ }
368+
369+ const stringify = build ( schema )
370+ const output = stringify ( object )
371+
372+ try {
373+ JSON . parse ( output )
374+ t . pass ( )
375+ } catch ( e ) {
376+ t . fail ( )
377+ }
378+
379+ t . equal ( '{"winter":{"is":{"coming":{"where":"to town"}}}}' , output )
380+ } )
You can’t perform that action at this time.
0 commit comments