@@ -36,6 +36,18 @@ describe("Schema with circular (recursive) $refs", () => {
36
36
expect ( schema . definitions . child . properties . pet ) . to . equal ( schema . definitions . pet ) ;
37
37
} ) ;
38
38
39
+ it ( "should double dereference successfully" , async ( ) => {
40
+ const firstPassSchema = await $RefParser . dereference ( path . rel ( "specs/circular/circular-self.yaml" ) ) ;
41
+ let parser = new $RefParser ( ) ;
42
+ const schema = await parser . dereference ( firstPassSchema ) ;
43
+ expect ( schema ) . to . equal ( parser . schema ) ;
44
+ expect ( schema ) . to . deep . equal ( dereferencedSchema . self ) ;
45
+ // The "circular" flag should be set
46
+ expect ( parser . $refs . circular ) . to . equal ( true ) ;
47
+ // Reference equality
48
+ expect ( schema . definitions . child . properties . pet ) . to . equal ( schema . definitions . pet ) ;
49
+ } ) ;
50
+
39
51
it ( 'should produce the same results if "options.$refs.circular" is "ignore"' , async ( ) => {
40
52
let parser = new $RefParser ( ) ;
41
53
const schema = await parser . dereference ( path . rel ( "specs/circular/circular-self.yaml" ) , { dereference : { circular : "ignore" } } ) ;
@@ -103,6 +115,19 @@ describe("Schema with circular (recursive) $refs", () => {
103
115
expect ( schema . definitions . person . properties . pet ) . to . equal ( schema . definitions . pet ) ;
104
116
} ) ;
105
117
118
+ it ( "should double dereference successfully" , async ( ) => {
119
+ let parser = new $RefParser ( ) ;
120
+ const firstPassSchema = await $RefParser . dereference ( path . rel ( "specs/circular/circular-ancestor.yaml" ) ) ;
121
+ const schema = await parser . dereference ( firstPassSchema ) ;
122
+ expect ( schema ) . to . equal ( parser . schema ) ;
123
+ expect ( schema ) . to . deep . equal ( dereferencedSchema . ancestor . fullyDereferenced ) ;
124
+ // The "circular" flag should be set
125
+ expect ( parser . $refs . circular ) . to . equal ( true ) ;
126
+ // Reference equality
127
+ expect ( schema . definitions . person . properties . spouse ) . to . equal ( schema . definitions . person ) ;
128
+ expect ( schema . definitions . person . properties . pet ) . to . equal ( schema . definitions . pet ) ;
129
+ } ) ;
130
+
106
131
it ( 'should not dereference circular $refs if "options.$refs.circular" is "ignore"' , async ( ) => {
107
132
let parser = new $RefParser ( ) ;
108
133
const schema = await parser . dereference ( path . rel ( "specs/circular/circular-ancestor.yaml" ) , { dereference : { circular : "ignore" } } ) ;
@@ -174,6 +199,21 @@ describe("Schema with circular (recursive) $refs", () => {
174
199
. to . equal ( schema . definitions . parent ) ;
175
200
} ) ;
176
201
202
+ it ( "should double dereference successfully" , async ( ) => {
203
+ let parser = new $RefParser ( ) ;
204
+ const firstPassSchema = await $RefParser . dereference ( path . rel ( "specs/circular/circular-indirect.yaml" ) ) ;
205
+ const schema = await parser . dereference ( firstPassSchema ) ;
206
+ expect ( schema ) . to . equal ( parser . schema ) ;
207
+ expect ( schema ) . to . deep . equal ( dereferencedSchema . indirect . fullyDereferenced ) ;
208
+ // The "circular" flag should be set
209
+ expect ( parser . $refs . circular ) . to . equal ( true ) ;
210
+ // Reference equality
211
+ expect ( schema . definitions . parent . properties . children . items )
212
+ . to . equal ( schema . definitions . child ) ;
213
+ expect ( schema . definitions . child . properties . parents . items )
214
+ . to . equal ( schema . definitions . parent ) ;
215
+ } ) ;
216
+
177
217
it ( 'should not dereference circular $refs if "options.$refs.circular" is "ignore"' , async ( ) => {
178
218
let parser = new $RefParser ( ) ;
179
219
const schema = await parser . dereference ( path . rel ( "specs/circular/circular-indirect.yaml" ) , { dereference : { circular : "ignore" } } ) ;
@@ -245,6 +285,21 @@ describe("Schema with circular (recursive) $refs", () => {
245
285
. to . equal ( schema . definitions . child ) ;
246
286
} ) ;
247
287
288
+ it ( "should double dereference successfully" , async ( ) => {
289
+ let parser = new $RefParser ( ) ;
290
+ const firstPassSchema = await parser . dereference ( path . rel ( "specs/circular/circular-indirect-ancestor.yaml" ) ) ;
291
+ const schema = await parser . dereference ( firstPassSchema ) ;
292
+ expect ( schema ) . to . equal ( parser . schema ) ;
293
+ expect ( schema ) . to . deep . equal ( dereferencedSchema . indirectAncestor . fullyDereferenced ) ;
294
+ // The "circular" flag should be set
295
+ expect ( parser . $refs . circular ) . to . equal ( true ) ;
296
+ // Reference equality
297
+ expect ( schema . definitions . parent . properties . child )
298
+ . to . equal ( schema . definitions . child ) ;
299
+ expect ( schema . definitions . child . properties . children . items )
300
+ . to . equal ( schema . definitions . child ) ;
301
+ } ) ;
302
+
248
303
it ( 'should not dereference circular $refs if "options.$refs.circular" is "ignore"' , async ( ) => {
249
304
let parser = new $RefParser ( ) ;
250
305
const schema = await parser . dereference ( path . rel ( "specs/circular/circular-indirect-ancestor.yaml" ) , { dereference : { circular : "ignore" } } ) ;
0 commit comments