File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -800,39 +800,44 @@ if (typeof brutusin === "undefined") {
800
800
} ;
801
801
802
802
obj . getData = function ( ) {
803
- function removeEmptiesAndNulls ( object ) {
803
+ function removeEmptiesAndNulls ( object , schema ) {
804
804
if ( object instanceof Array ) {
805
805
if ( object . length === 0 ) {
806
806
return null ;
807
807
}
808
808
var clone = new Array ( ) ;
809
809
for ( var i = 0 ; i < object . length ; i ++ ) {
810
- clone [ i ] = removeEmptiesAndNulls ( object [ i ] ) ;
810
+ clone [ i ] = removeEmptiesAndNulls ( object [ i ] , schema . items ) ;
811
811
}
812
812
return clone ;
813
813
} else if ( object === "" ) {
814
814
return null ;
815
815
} else if ( object instanceof Object ) {
816
816
var clone = new Object ( ) ;
817
+ var nonEmpty = false ;
817
818
for ( var prop in object ) {
818
819
if ( prop . startsWith ( "$" ) && prop . endsWith ( "$" ) ) {
819
820
continue ;
820
821
}
821
- var value = removeEmptiesAndNulls ( object [ prop ] ) ;
822
+ var value = removeEmptiesAndNulls ( object [ prop ] , schema . properties [ prop ] ) ;
822
823
if ( value !== null ) {
823
824
clone [ prop ] = value ;
825
+ nonEmpty = true ;
824
826
}
825
827
}
826
- return clone ;
828
+ if ( nonEmpty || schema . required ) {
829
+ return clone ;
830
+ } else {
831
+ return null ;
832
+ }
827
833
} else {
828
834
return object ;
829
835
}
830
836
}
831
837
if ( ! container ) {
832
838
return null ;
833
839
} else {
834
- return removeEmptiesAndNulls ( data ) ;
835
- ;
840
+ return removeEmptiesAndNulls ( data , schema ) ;
836
841
}
837
842
} ;
838
843
You can’t perform that action at this time.
0 commit comments