11export function getBlankObject ( schema ) {
22 let keys = { } ;
33
4- for ( let key in schema . keys ) {
5- let value = schema . keys [ key ] ;
4+ let schema_keys = schema . keys || schema . properties ;
5+
6+ for ( let key in schema_keys ) {
7+ let value = schema_keys [ key ] ;
68 let type = value . type ;
79
10+ if ( type === 'list' )
11+ type = 'array' ;
12+ else if ( type === 'dict' )
13+ type = 'object' ;
14+
815 if ( type === 'array' )
916 keys [ key ] = getBlankArray ( value ) ;
1017 else if ( type === 'object' )
@@ -23,6 +30,11 @@ export function getBlankArray(schema) {
2330 let items = [ ] ;
2431 let type = schema . items . type ;
2532
33+ if ( type === 'list' )
34+ type = 'array' ;
35+ else if ( type === 'dict' )
36+ type = 'object' ;
37+
2638 if ( type === 'array' )
2739 items . push ( getBlankArray ( schema . items ) )
2840 else if ( type === 'object' )
@@ -37,14 +49,21 @@ export function getBlankArray(schema) {
3749
3850
3951export function getBlankData ( schema ) {
40- if ( schema . type === 'array' ) {
52+ let type = schema . type ;
53+
54+ if ( type === 'list' )
55+ type = 'array' ;
56+ else if ( type === 'dict' )
57+ type = 'object' ;
58+
59+ if ( type === 'array' ) {
4160 return getBlankArray ( schema ) ;
4261 }
43- else if ( schema . type === 'object' ) {
62+ else if ( type === 'object' ) {
4463 return getBlankObject ( schema ) ;
45- } else if ( schema . type === 'string' ) {
64+ } else if ( type === 'string' ) {
4665 return '' ;
47- } else if ( schema . type === 'number' ) {
66+ } else if ( type === 'number' ) {
4867 return '' ;
4968 }
5069}
@@ -54,12 +73,19 @@ export function getBlankData(schema) {
5473function getSyncedArray ( data , schema ) {
5574 let newData = JSON . parse ( JSON . stringify ( data ) ) ;
5675
76+ let type = schema . items . type ;
77+
78+ if ( type === 'list' )
79+ type = 'array' ;
80+ else if ( type === 'dict' )
81+ type = 'object' ;
82+
5783 for ( let i = 0 ; i < data . length ; i ++ ) {
5884 let item = data [ i ] ;
5985
60- if ( schema . items . type === 'array' ) {
86+ if ( type === 'array' ) {
6187 newData [ i ] = getSyncedArray ( item , schema . items ) ;
62- } else if ( schema . items . type === 'object' ) {
88+ } else if ( type === 'object' ) {
6389 newData [ i ] = getSyncedObject ( item , schema . items ) ;
6490 }
6591 }
@@ -71,25 +97,33 @@ function getSyncedArray(data, schema) {
7197function getSyncedObject ( data , schema ) {
7298 let newData = JSON . parse ( JSON . stringify ( data ) ) ;
7399
74- let keys = [ ...Object . keys ( schema . keys ) ] ;
100+ let schema_keys = schema . keys || schema . properties ;
101+
102+ let keys = [ ...Object . keys ( schema_keys ) ] ;
75103
76104 for ( let i = 0 ; i < keys . length ; i ++ ) {
77105 let key = keys [ i ] ;
78- let schemaValue = schema . keys [ key ] ;
106+ let schemaValue = schema_keys [ key ] ;
107+ let type = schemaValue . type ;
108+
109+ if ( type === 'list' )
110+ type = 'array' ;
111+ else if ( type === 'dict' )
112+ type = 'object' ;
79113
80114 if ( ! data . hasOwnProperty ( key ) ) {
81- if ( schemaValue . type === 'string' )
115+ if ( type === 'string' )
82116 newData [ key ] = '' ;
83- else if ( schemaValue . type === 'array' )
117+ else if ( type === 'array' )
84118 newData [ key ] = getSyncedArray ( [ ] , schemaValue ) ;
85- else if ( schemaValue . type === 'object' )
119+ else if ( type === 'object' )
86120 newData [ key ] = getSyncedObject ( { } , schemaValue ) ;
87121 } else {
88- if ( schemaValue . type === 'string' )
122+ if ( type === 'string' )
89123 newData [ key ] = data [ key ] ;
90- else if ( schemaValue . type === 'array' )
124+ else if ( type === 'array' )
91125 newData [ key ] = getSyncedArray ( data [ key ] , schemaValue ) ;
92- else if ( schemaValue . type === 'object' )
126+ else if ( type === 'object' )
93127 newData [ key ] = getSyncedObject ( data [ key ] , schemaValue ) ;
94128 }
95129
@@ -102,9 +136,16 @@ function getSyncedObject(data, schema) {
102136export function getSyncedData ( data , schema ) {
103137 // adds those keys to data which are in schema but not in data
104138
105- if ( schema . type === 'array' ) {
139+ let type = schema . type ;
140+
141+ if ( type === 'list' )
142+ type = 'array' ;
143+ else if ( type === 'dict' )
144+ type = 'object' ;
145+
146+ if ( type === 'array' ) {
106147 return getSyncedArray ( data , schema ) ;
107- } else if ( schema . type === 'object' ) {
148+ } else if ( type === 'object' ) {
108149 return getSyncedObject ( data , schema ) ;
109150 }
110151
0 commit comments