@@ -14,7 +14,7 @@ describe("traverse", () => {
14
14
it ( "default mutate" , ( ) => {
15
15
const testSchema = {
16
16
type : "string"
17
- } ;
17
+ } as JSONSchema ;
18
18
const mutator = ( ) => ( { hello : "world" } ) ;
19
19
20
20
const result = traverse ( testSchema , mutator ) as any ;
@@ -26,7 +26,7 @@ describe("traverse", () => {
26
26
it ( "mutate does not affect traversal" , ( ) => {
27
27
const testSchema = {
28
28
type : "object"
29
- } ;
29
+ } as JSONSchema ;
30
30
31
31
const mutator = jest . fn ( ( s : JSONSchemaObject ) => ( {
32
32
...s ,
@@ -45,7 +45,7 @@ describe("traverse", () => {
45
45
it ( "merge does not affect traversal" , ( ) => {
46
46
const testSchema = {
47
47
type : "object"
48
- } ;
48
+ } as JSONSchema ;
49
49
const mergeProducer = jest . fn ( ( s : JSONSchemaObject ) => ( {
50
50
...s ,
51
51
properties : {
@@ -106,7 +106,7 @@ describe("traverse", () => {
106
106
} ) ;
107
107
108
108
it ( "accepts boolean as valid schema in a nested schema" , ( ) => {
109
- const schema = { type : "object" , properties : { a : true , b : false } } ;
109
+ const schema = { type : "object" , properties : { a : true , b : false } } as JSONSchema ;
110
110
const mockMutation = jest . fn ( ( s ) => s ) ;
111
111
traverse ( schema , mockMutation ) ;
112
112
expect ( mockMutation ) . toHaveBeenCalledTimes ( 3 ) ;
@@ -121,7 +121,7 @@ describe("traverse", () => {
121
121
const schema = {
122
122
type : "object" ,
123
123
patternProperties : { "*." : a , "x-^" : b }
124
- } ;
124
+ } as JSONSchema ;
125
125
const mockMutation = jest . fn ( ( s ) => s ) ;
126
126
traverse ( schema , mockMutation ) ;
127
127
expect ( mockMutation ) . toHaveBeenCalledTimes ( 3 ) ;
@@ -133,7 +133,7 @@ describe("traverse", () => {
133
133
it ( "allows booleans that are created via boolean class and new" , ( ) => {
134
134
const a = new Boolean ( true ) ;
135
135
const b = new Boolean ( false ) ;
136
- const schema = { type : "object" , properties : { a, b } } ;
136
+ const schema = { type : "object" , properties : { a, b } } as JSONSchema ;
137
137
const mockMutation = jest . fn ( ( s ) => s ) ;
138
138
traverse ( schema , mockMutation ) ;
139
139
expect ( mockMutation ) . toHaveBeenCalledTimes ( 3 ) ;
@@ -148,7 +148,7 @@ describe("traverse", () => {
148
148
} ) ;
149
149
150
150
it ( "items is a boolean" , ( ) => {
151
- const schema = { type : "array" , items : true } ;
151
+ const schema = { type : "array" , items : true } as JSONSchema ;
152
152
const mockMutation = jest . fn ( ( s ) => s ) ;
153
153
traverse ( schema , mockMutation ) ;
154
154
expect ( mockMutation ) . toHaveBeenCalledTimes ( 2 ) ;
@@ -168,7 +168,7 @@ describe("traverse", () => {
168
168
}
169
169
}
170
170
}
171
- } ;
171
+ } as JSONSchema ;
172
172
const mockMutation = jest . fn ( ( s ) => s ) ;
173
173
traverse ( schema , mockMutation ) ;
174
174
expect ( mockMutation ) . toHaveBeenCalledTimes ( 6 ) ;
@@ -266,7 +266,7 @@ describe("traverse", () => {
266
266
267
267
describe ( "schema.type being an array" , ( ) => {
268
268
it ( "allows type to be an array" , ( ) => {
269
- const schema = { type : [ "boolean" , "string" ] , title : "gotimebucko" } ;
269
+ const schema = { type : [ "boolean" , "string" ] , title : "gotimebucko" } as JSONSchema ;
270
270
const mockMutation = jest . fn ( ( s ) => s ) ;
271
271
traverse ( schema , mockMutation ) ;
272
272
expect ( mockMutation ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -281,7 +281,7 @@ describe("traverse", () => {
281
281
b : { type : "integer" }
282
282
} ,
283
283
items : { type : "string" }
284
- } ;
284
+ } as JSONSchema ;
285
285
const mockMutation = jest . fn ( ( s ) => s ) ;
286
286
traverse ( schema , mockMutation ) ;
287
287
expect ( mockMutation ) . toHaveBeenCalledTimes ( 4 ) ;
@@ -293,12 +293,12 @@ describe("traverse", () => {
293
293
const schema = { type : "object" , properties : { foo : { } } } ;
294
294
schema . properties . foo = schema ;
295
295
const mockMutation = jest . fn ( ( s ) => s ) ;
296
- traverse ( schema , mockMutation ) ;
296
+ traverse ( schema as JSONSchema , mockMutation ) ;
297
297
expect ( mockMutation ) . toHaveBeenCalledTimes ( 1 ) ;
298
298
} ) ;
299
299
300
300
it ( "does not follow $refs" , ( ) => {
301
- const schema = { type : "object" , properties : { foo : { $ref : "#" } } } ;
301
+ const schema = { type : "object" , properties : { foo : { $ref : "#" } } } as JSONSchema ;
302
302
const mockMutation = jest . fn ( ( s ) => s ) ;
303
303
traverse ( schema , mockMutation ) ;
304
304
expect ( mockMutation ) . toHaveBeenCalledTimes ( 2 ) ;
@@ -323,7 +323,7 @@ describe("traverse", () => {
323
323
} ;
324
324
schema . properties . foo . items [ 0 ] . items = schema ;
325
325
const mockMutation = jest . fn ( ( s ) => s ) ;
326
- traverse ( schema , mockMutation ) ;
326
+ traverse ( schema as JSONSchema , mockMutation ) ;
327
327
expect ( mockMutation ) . toHaveBeenCalledTimes ( 3 ) ;
328
328
} ) ;
329
329
@@ -351,7 +351,7 @@ describe("traverse", () => {
351
351
} ;
352
352
schema . properties . foo . anyOf [ 0 ] . items . properties . baz = schema . properties . foo ;
353
353
const mockMutation = jest . fn ( ( s ) => s ) ;
354
- traverse ( schema , mockMutation ) ;
354
+ traverse ( schema as JSONSchema , mockMutation ) ;
355
355
expect ( mockMutation ) . toHaveBeenCalledTimes ( 4 ) ;
356
356
} ) ;
357
357
@@ -387,7 +387,7 @@ describe("traverse", () => {
387
387
schema . properties . foo . anyOf [ 0 ] . items . properties . baz = schema ;
388
388
schema . properties . bar . allOf [ 0 ] . properties . baz = schema . properties . foo . anyOf [ 0 ] ;
389
389
const mockMutation = jest . fn ( ( s ) => s ) ;
390
- traverse ( schema , mockMutation ) ;
390
+ traverse ( schema as JSONSchema , mockMutation ) ;
391
391
expect ( mockMutation ) . toHaveBeenCalledTimes ( 6 ) ;
392
392
} ) ;
393
393
@@ -471,7 +471,7 @@ describe("traverse", () => {
471
471
} ;
472
472
schema . properties . foo . anyOf [ 0 ] . items . properties . baz = schema . properties . foo ;
473
473
const mockMutation = jest . fn ( ( s ) => s ) ;
474
- traverse ( schema , mockMutation ) ;
474
+ traverse ( schema as JSONSchema , mockMutation ) ;
475
475
expect ( mockMutation ) . toHaveBeenCalledTimes ( 4 ) ;
476
476
} ) ;
477
477
@@ -550,7 +550,7 @@ describe("traverse", () => {
550
550
551
551
const mockMutation = jest . fn ( ( mockS ) => mockS ) ;
552
552
553
- traverse ( testSchema , mockMutation , { mutable : true } ) ;
553
+ traverse ( testSchema as JSONSchema , mockMutation , { mutable : true } ) ;
554
554
555
555
expect ( mockMutation ) . toHaveBeenCalledWith ( testSchema . properties . foo , true , "/properties/foo" ) ;
556
556
expect ( mockMutation ) . not . toHaveBeenCalledWith ( testSchema . properties . foo , false , "/properties/foo" ) ;
@@ -568,7 +568,7 @@ describe("traverse", () => {
568
568
569
569
const mockMutation = jest . fn ( ( mockS ) => mockS ) ;
570
570
571
- traverse ( testSchema , mockMutation , { mutable : true } ) ;
571
+ traverse ( testSchema as JSONSchema , mockMutation , { mutable : true } ) ;
572
572
573
573
expect ( mockMutation ) . toHaveBeenCalledWith ( testSchema , true , "" ) ;
574
574
expect ( mockMutation ) . not . toHaveBeenCalledWith ( testSchema , false , "" ) ;
@@ -589,7 +589,7 @@ describe("traverse", () => {
589
589
590
590
const mockMutation = jest . fn ( ( mockS ) => mockS ) ;
591
591
592
- traverse ( testSchema , mockMutation , { mutable : false } ) ;
592
+ traverse ( testSchema as JSONSchema , mockMutation , { mutable : false } ) ;
593
593
594
594
expect ( mockMutation ) . toHaveBeenCalledWith ( testSchema , true , "" ) ;
595
595
expect ( mockMutation ) . not . toHaveBeenCalledWith ( testSchema , false , "" ) ;
@@ -612,7 +612,7 @@ describe("traverse", () => {
612
612
} ;
613
613
const mockMutation = jest . fn ( ( mockS ) => mockS ) ;
614
614
615
- traverse ( testSchema , mockMutation , { bfs : true , } ) ;
615
+ traverse ( testSchema as JSONSchema , mockMutation , { bfs : true , } ) ;
616
616
617
617
const expectedPath1 = "/properties/foo/items/0" ;
618
618
const expectedPath2 = "/properties/foo/items/1" ;
@@ -637,7 +637,7 @@ describe("traverse", () => {
637
637
} ;
638
638
const mockMutation = jest . fn ( ( mockS ) => mockS ) ;
639
639
640
- traverse ( testSchema , mockMutation , { bfs : true , mutable : true } ) ;
640
+ traverse ( testSchema as JSONSchema , mockMutation , { bfs : true , mutable : true } ) ;
641
641
642
642
const expectedPath1 = "/properties/foo/items/0" ;
643
643
const expectedPath2 = "/properties/foo/items/1" ;
@@ -657,7 +657,7 @@ describe("Mutability settings", () => {
657
657
foo : { type : "string" } ,
658
658
bar : { type : "number" }
659
659
}
660
- } ;
660
+ } as JSONSchema ;
661
661
662
662
const frozenS = Object . freeze ( s ) ;
663
663
@@ -681,7 +681,7 @@ describe("Mutability settings", () => {
681
681
682
682
const frozenS = Object . freeze ( s ) ;
683
683
684
- const result = traverse ( frozenS , ( ss ) => ss , { mutable : false } ) as JSONSchemaObject ;
684
+ const result = traverse ( frozenS as JSONSchema , ( ss ) => ss , { mutable : false } ) as JSONSchemaObject ;
685
685
686
686
expect ( frozenS ) . not . toBe ( result ) ;
687
687
expect ( ( result . properties as Properties ) . foo ) . toBe ( result ) ;
@@ -700,7 +700,7 @@ describe("Mutability settings", () => {
700
700
701
701
const frozenS = Object . freeze ( s ) ;
702
702
703
- const result = traverse ( frozenS , ( ss ) => ss , { mutable : false , skipFirstMutation : true } ) as JSONSchemaObject ;
703
+ const result = traverse ( frozenS as JSONSchema , ( ss ) => ss , { mutable : false , skipFirstMutation : true } ) as JSONSchemaObject ;
704
704
705
705
expect ( frozenS ) . not . toBe ( result ) ;
706
706
expect ( ( result . properties as Properties ) . foo ) . not . toBe ( frozenS . properties . foo ) ;
@@ -723,7 +723,7 @@ describe("Mutability settings", () => {
723
723
724
724
const frozenS = Object . freeze ( s ) ;
725
725
726
- const result = traverse ( frozenS , ( ss ) => {
726
+ const result = traverse ( frozenS as JSONSchema , ( ss ) => {
727
727
if ( ss === true || ss === false ) { return ss ; }
728
728
return { hello : "world" , ...ss } ;
729
729
} , { mutable : false , bfs : true } ) as JSONSchemaObject ;
@@ -754,7 +754,7 @@ describe("Mutability settings", () => {
754
754
755
755
const frozenS = Object . freeze ( s ) ;
756
756
757
- const result = traverse ( frozenS , ( ss ) => {
757
+ const result = traverse ( frozenS as JSONSchema , ( ss ) => {
758
758
if ( ss === true || ss === false ) { return ss ; }
759
759
return { hello : "world" , ...ss } ;
760
760
} , { mutable : false , bfs : true , skipFirstMutation : true } ) as JSONSchemaObject ;
@@ -781,7 +781,7 @@ describe("Mutability settings", () => {
781
781
s . properties . foo = s ;
782
782
783
783
784
- const result = traverse ( s , ( ss ) => ss , { mutable : true } ) as JSONSchemaObject ;
784
+ const result = traverse ( s as JSONSchema , ( ss ) => ss , { mutable : true } ) as JSONSchemaObject ;
785
785
786
786
expect ( s ) . toBe ( result ) ;
787
787
expect ( ( result . properties as Properties ) . foo ) . toBe ( result ) ;
@@ -797,7 +797,7 @@ describe("Mutability settings", () => {
797
797
}
798
798
} ;
799
799
800
- const result = traverse ( s , ( ss : any ) => { ss . hello = "world" ; return ss ; } , { mutable : true , skipFirstMutation : true } ) as JSONSchemaObject ;
800
+ const result = traverse ( s as JSONSchema , ( ss : any ) => { ss . hello = "world" ; return ss ; } , { mutable : true , skipFirstMutation : true } ) as JSONSchemaObject ;
801
801
802
802
expect ( s ) . toBe ( result ) ;
803
803
expect ( ( s as any ) . hello ) . not . toBeDefined ( ) ;
@@ -812,14 +812,12 @@ describe("Mutability settings", () => {
812
812
}
813
813
} ;
814
814
815
- const result = traverse ( s , ( ss : any ) => { ss . hello = "world" ; return ss ; } , { mutable : true , bfs : true } ) as JSONSchemaObject ;
815
+ const result = traverse ( s as JSONSchema , ( ss : any ) => { ss . hello = "world" ; return ss ; } , { mutable : true , bfs : true } ) as JSONSchemaObject ;
816
816
817
817
expect ( s ) . toBe ( result ) ;
818
818
expect ( ( s as any ) . hello ) . toBe ( "world" ) ;
819
819
expect ( ( s . properties . foo as any ) . hello ) . toBe ( "world" )
820
820
expect ( ( result . properties as Properties ) . foo ) . toBe ( s . properties . foo ) ;
821
821
} ) ;
822
-
823
822
} ) ;
824
-
825
823
} ) ;
0 commit comments