@@ -273,7 +273,7 @@ export class ObjectSchemaTreeNode extends NonLeafSchemaTreeNode<{[key: string]:
273
273
const propertySchema = schema [ 'properties' ] [ name ] ;
274
274
this . _children [ name ] = this . _createChildProperty (
275
275
name ,
276
- value ? value [ name ] : null ,
276
+ value ? value [ name ] : undefined ,
277
277
forward ? ( forward as ObjectSchemaTreeNode ) . children [ name ] : null ,
278
278
propertySchema ) ;
279
279
}
@@ -331,7 +331,7 @@ export class ArraySchemaTreeNode extends NonLeafSchemaTreeNode<Array<any>> {
331
331
332
332
// Keep the item's schema as a schema node. This is important to keep type information.
333
333
this . _itemPrototype = this . _createChildProperty (
334
- '' , null , null , metaData . schema [ 'items' ] , false ) ;
334
+ '' , undefined , null , metaData . schema [ 'items' ] , false ) ;
335
335
}
336
336
337
337
_set ( value : any , init : boolean , force : boolean ) {
@@ -398,7 +398,7 @@ export abstract class LeafSchemaTreeNode<T> extends SchemaTreeNode<T> {
398
398
399
399
constructor ( metaData : TreeNodeConstructorArgument < T > ) {
400
400
super ( metaData ) ;
401
- this . _defined = ! ( metaData . value === undefined || metaData . value === null ) ;
401
+ this . _defined = metaData . value !== undefined ;
402
402
if ( 'default' in metaData . schema ) {
403
403
this . _default = this . convert ( metaData . schema [ 'default' ] ) ;
404
404
}
@@ -463,8 +463,8 @@ class StringSchemaTreeNode extends LeafSchemaTreeNode<string> {
463
463
}
464
464
465
465
466
- class EnumSchemaTreeNode extends StringSchemaTreeNode {
467
- constructor ( metaData : TreeNodeConstructorArgument < string > ) {
466
+ class EnumSchemaTreeNode extends LeafSchemaTreeNode < any > {
467
+ constructor ( metaData : TreeNodeConstructorArgument < any > ) {
468
468
super ( metaData ) ;
469
469
470
470
if ( ! Array . isArray ( metaData . schema [ 'enum' ] ) ) {
@@ -480,18 +480,24 @@ class EnumSchemaTreeNode extends StringSchemaTreeNode {
480
480
return this . _schema [ 'enum' ] . some ( ( v : string ) => v === value ) ;
481
481
}
482
482
483
+ get items ( ) { return this . _schema [ 'enum' ] ; }
484
+
483
485
isCompatible ( v : any ) {
484
- return ( typeof v == 'string' || v instanceof String ) && this . _isInEnum ( '' + v ) ;
486
+ return this . _isInEnum ( v ) ;
485
487
}
486
488
convert ( v : any ) {
487
489
if ( v === undefined ) {
488
490
return undefined ;
489
491
}
490
- if ( v === null || ! this . _isInEnum ( '' + v ) ) {
491
- return null ;
492
+ if ( ! this . _isInEnum ( v ) ) {
493
+ return undefined ;
492
494
}
493
- return '' + v ;
495
+ return v ;
494
496
}
497
+
498
+ get type ( ) { return 'any' ; }
499
+ get tsType ( ) : null { return null ; }
500
+ serialize ( serializer : Serializer ) { serializer . outputEnum ( this ) ; }
495
501
}
496
502
497
503
0 commit comments