File tree 2 files changed +18
-1
lines changed
src/core/plugins/json-schema-2020-12-samples/fn/core
test/unit/core/plugins/json-schema-2020-12-samples
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,10 @@ export const foldType = (type) => {
67
67
} else if ( type . includes ( "object" ) ) {
68
68
return "object"
69
69
} else {
70
- const pickedType = randomPick ( type )
70
+ const notNullTypes = type . filter ( ( t ) => t !== "null" )
71
+ const pickedType = randomPick (
72
+ notNullTypes . length > 0 ? notNullTypes : type
73
+ )
71
74
if ( ALL_TYPES . includes ( pickedType ) ) {
72
75
return pickedType
73
76
}
Original file line number Diff line number Diff line change @@ -373,6 +373,20 @@ describe("sampleFromSchema", () => {
373
373
expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
374
374
} )
375
375
376
+ it ( "should handle nullable primitive types defined as list of types" , function ( ) {
377
+ const sample = ( schema ) => sampleFromSchema ( fromJS ( schema ) )
378
+
379
+ expect ( sample ( { type : [ "string" , "null" ] } ) ) . toStrictEqual ( "string" )
380
+ expect ( sample ( { type : [ "null" , "string" ] } ) ) . toStrictEqual ( "string" )
381
+ expect ( sample ( { type : [ "number" , "null" ] } ) ) . toStrictEqual ( 0 )
382
+ expect ( sample ( { type : [ "null" , "number" ] } ) ) . toStrictEqual ( 0 )
383
+ expect ( sample ( { type : [ "integer" , "null" ] } ) ) . toStrictEqual ( 0 )
384
+ expect ( sample ( { type : [ "null" , "integer" ] } ) ) . toStrictEqual ( 0 )
385
+ expect ( sample ( { type : [ "boolean" , "null" ] } ) ) . toStrictEqual ( true )
386
+ expect ( sample ( { type : [ "null" , "boolean" ] } ) ) . toStrictEqual ( true )
387
+ expect ( sample ( { type : [ "null" ] } ) ) . toStrictEqual ( null )
388
+ } )
389
+
376
390
it ( "should return const value" , function ( ) {
377
391
const definition = fromJS ( { const : 3 } )
378
392
const expected = 3
You can’t perform that action at this time.
0 commit comments