@@ -98,7 +98,7 @@ export class IdentitiesValidationService {
9898
9999 // Validate each attribute
100100 for ( const key of attributesKeys ) {
101- const validationError = await this . validateAttribute ( key , attributes [ key ] ) ;
101+ const validationError = await this . validateAttribute ( key , attributes [ key ] , attributes ) ;
102102 if ( validationError ) {
103103 validations [ key ] = validationError ;
104104 reject = true ;
@@ -119,9 +119,33 @@ export class IdentitiesValidationService {
119119 * @param attribute - The attribute value to validate.
120120 * @returns A promise that resolves with an error message if validation fails, otherwise null.
121121 */
122- public async validateAttribute ( key : string , attribute : any ) : Promise < string | null > {
122+ public async validateAttribute ( key : string , attribute : any , data : any ) : Promise < string | null > {
123123 const path = this . resolveConfigPath ( key ) ;
124- const schema : ConfigObjectSchemaDTO = parse ( readFileSync ( path , 'utf8' ) ) ;
124+ const schema : any = parse ( readFileSync ( path , 'utf8' ) ) ;
125+
126+ for ( const [ index , def ] of Object . entries ( schema ?. properties || { } ) ) {
127+ if ( typeof data [ key ] [ index ] === 'undefined' || data [ key ] [ index ] === null ) {
128+ switch ( ( def as any ) . type ) {
129+ case 'array' :
130+ data [ key ] [ index ] = [ ] ;
131+ break ;
132+
133+ case 'object' :
134+ data [ key ] [ index ] = { } ;
135+ break ;
136+
137+ case 'number' :
138+ data [ key ] [ index ] = 0 ;
139+ break ;
140+
141+ default :
142+ data [ key ] [ index ] = '' ;
143+ break ;
144+ }
145+ }
146+ }
147+
148+ console . log ( data [ key ] ) ;
125149
126150 const yupSchema = buildYup ( schema , { noSortEdges : true } ) ;
127151 try {
0 commit comments