@@ -17,18 +17,22 @@ describe('nullable', () => {
17
17
} ) ;
18
18
} ) ;
19
19
20
- it ( 'supports nullables inside sub-schemas' , async ( { expect } ) => {
21
- const schema = {
22
- $schema : 'http://json-schema.org/draft-04/schema#' ,
23
- oneOf : [ { type : 'string' } , { type : 'null' } ] ,
24
- } satisfies JSONSchema4 ;
20
+ it . each ( [ 'oneOf' , 'anyOf' ] as const ) (
21
+ 'supports nullables inside sub-schemas %s' ,
22
+ async ( key ) => {
23
+ const schema = {
24
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
25
+ [ key ] : [ { type : 'string' } , { type : 'null' } ] ,
26
+ } satisfies JSONSchema4 ;
25
27
26
- const result = await convert ( schema ) ;
28
+ const result = await convert ( schema ) ;
29
+
30
+ expect ( result ) . toEqual ( {
31
+ [ key ] : [ { type : 'string' , nullable : true } ] ,
32
+ } ) ;
33
+ }
34
+ ) ;
27
35
28
- expect ( result ) . toEqual ( {
29
- oneOf : [ { type : 'string' , nullable : true } ] ,
30
- } ) ;
31
- } ) ;
32
36
it ( 'supports nullables inside definitions' , async ( { expect } ) => {
33
37
const schema = {
34
38
$schema : 'http://json-schema.org/draft-07/schema#' ,
@@ -149,59 +153,62 @@ describe('nullable', () => {
149
153
} ) ;
150
154
} ) ;
151
155
152
- it ( 'adds nullable for types with null' , async ( { expect } ) => {
153
- const schema = {
154
- $schema : 'http://json-schema.org/draft-04/schema#' ,
155
- title : 'NullExample' ,
156
- description : 'Null Example' ,
157
- oneOf : [
158
- {
159
- type : 'object' ,
160
- properties : {
161
- foo : {
162
- type : 'string' ,
156
+ it . each ( [ 'oneOf' , 'anyOf' ] as const ) (
157
+ 'adds nullable for types with null' ,
158
+ async ( key ) => {
159
+ const schema = {
160
+ $schema : 'http://json-schema.org/draft-04/schema#' ,
161
+ title : 'NullExample' ,
162
+ description : 'Null Example' ,
163
+ [ key ] : [
164
+ {
165
+ type : 'object' ,
166
+ properties : {
167
+ foo : {
168
+ type : 'string' ,
169
+ } ,
163
170
} ,
164
171
} ,
165
- } ,
166
- {
167
- type : 'object' ,
168
- properties : {
169
- bar : {
170
- type : 'number' ,
172
+ {
173
+ type : 'object' ,
174
+ properties : {
175
+ bar : {
176
+ type : 'number' ,
177
+ } ,
171
178
} ,
172
179
} ,
173
- } ,
174
- {
175
- type : 'null' ,
176
- } ,
177
- ] ,
178
- } satisfies JSONSchema4 ;
180
+ {
181
+ type : 'null' ,
182
+ } ,
183
+ ] ,
184
+ } satisfies JSONSchema4 ;
179
185
180
- const result = await convert ( schema ) ;
186
+ const result = await convert ( schema ) ;
181
187
182
- expect ( result ) . toEqual ( {
183
- title : 'NullExample' ,
184
- description : 'Null Example' ,
185
- oneOf : [
186
- {
187
- type : 'object' ,
188
- properties : {
189
- foo : {
190
- type : 'string' ,
188
+ expect ( result ) . toEqual ( {
189
+ title : 'NullExample' ,
190
+ description : 'Null Example' ,
191
+ [ key ] : [
192
+ {
193
+ type : 'object' ,
194
+ properties : {
195
+ foo : {
196
+ type : 'string' ,
197
+ } ,
191
198
} ,
199
+ nullable : true ,
192
200
} ,
193
- nullable : true ,
194
- } ,
195
- {
196
- type : 'object' ,
197
- properties : {
198
- bar : {
199
- type : 'number' ,
201
+ {
202
+ type : 'object' ,
203
+ properties : {
204
+ bar : {
205
+ type : 'number' ,
206
+ } ,
200
207
} ,
208
+ nullable : true ,
201
209
} ,
202
- nullable : true ,
203
- } ,
204
- ] ,
205
- } ) ;
206
- } ) ;
210
+ ] ,
211
+ } ) ;
212
+ }
213
+ ) ;
207
214
} ) ;
0 commit comments