@@ -127,7 +127,7 @@ test('not fail on null sub-object declared nullable', (t) => {
127
127
t . equal ( '{"product":null}' , stringify ( object ) )
128
128
} )
129
129
130
- test ( 'throw an error on non nullable null sub-object' , ( t ) => {
130
+ test ( 'on non nullable null sub-object it should coerce to {} ' , ( t ) => {
131
131
t . plan ( 1 )
132
132
133
133
const stringify = build ( {
@@ -148,10 +148,12 @@ test('throw an error on non nullable null sub-object', (t) => {
148
148
const object = {
149
149
product : null
150
150
}
151
- t . throws ( ( ) => { stringify ( object ) } )
151
+
152
+ const result = stringify ( object )
153
+ t . equal ( result , JSON . stringify ( { product : { } } ) )
152
154
} )
153
155
154
- test ( 'throw an error on non nullable null object' , ( t ) => {
156
+ test ( 'on non nullable null object it should coerce to {} ' , ( t ) => {
155
157
t . plan ( 1 )
156
158
157
159
const stringify = build ( {
@@ -170,5 +172,32 @@ test('throw an error on non nullable null object', (t) => {
170
172
}
171
173
}
172
174
} )
173
- t . throws ( ( ) => { stringify ( null ) } )
175
+
176
+ const result = stringify ( null )
177
+ t . equal ( result , '{}' )
178
+ } )
179
+
180
+ test ( 'on non-nullable null object it should skip rendering, skipping required fields checks' , ( t ) => {
181
+ t . plan ( 1 )
182
+
183
+ const stringify = build ( {
184
+ title : 'simple object' ,
185
+ nullable : false ,
186
+ type : 'object' ,
187
+ properties : {
188
+ product : {
189
+ nullable : false ,
190
+ type : 'object' ,
191
+ properties : {
192
+ name : {
193
+ type : 'string'
194
+ }
195
+ }
196
+ }
197
+ } ,
198
+ required : [ 'product' ]
199
+ } )
200
+
201
+ const result = stringify ( null )
202
+ t . equal ( result , '{}' )
174
203
} )
0 commit comments