@@ -22,7 +22,7 @@ module.exports = class JSONAPISerializer {
2222 } ) ) . default ( { } ) ,
2323 topLevelLinks : joi . object ( ) . default ( { } ) ,
2424 topLevelMeta : joi . object ( ) . default ( { } ) ,
25- convertCase : joi . string ( ) ,
25+ convertCase : joi . string ( ) . valid ( 'kebab-case' , 'snake_case' , 'camelCase' ) ,
2626 } ) . required ( ) ;
2727
2828 const validated = joi . validate ( options , optionsSchema ) ;
@@ -115,7 +115,7 @@ module.exports = class JSONAPISerializer {
115115 let serializedAttributes = _ . pick ( data , _ . difference ( Object . keys ( data ) , _ . concat ( [ options . id ] , Object . keys ( options . relationships ) , options . blacklist ) ) ) ;
116116
117117 if ( options . convertCase ) {
118- serializedAttributes = this . convertCase ( serializedAttributes , options . convertCase ) ;
118+ serializedAttributes = this . _convertCase ( serializedAttributes , options . convertCase ) ;
119119 }
120120
121121 return serializedAttributes ;
@@ -132,7 +132,7 @@ module.exports = class JSONAPISerializer {
132132 data : this . serializeRelationship ( rOptions . type , data [ relationship ] , this . schemas [ options . relationships [ relationship ] . type ] [ schema ] , included ) ,
133133 } ;
134134
135- relationship = ( options . convertCase ) ? this . convertCase ( relationship , options . convertCase ) : relationship ;
135+ relationship = ( options . convertCase ) ? this . _convertCase ( relationship , options . convertCase ) : relationship ;
136136
137137 _ . set ( serializedRelationships , relationship , serializeRelationship ) ;
138138 } ) ;
@@ -187,14 +187,14 @@ module.exports = class JSONAPISerializer {
187187 return ! _ . isEmpty ( processedOptions ) ? processedOptions : undefined ;
188188 }
189189
190- convertCase ( data , convertCaseOptions ) {
190+ _convertCase ( data , convertCaseOptions ) {
191191 let converted ;
192192 if ( _ . isArray ( data ) || _ . isPlainObject ( data ) ) {
193193 converted = _ . transform ( data , ( result , value , key ) => {
194194 if ( _ . isArray ( value ) || _ . isPlainObject ( value ) ) {
195- result [ this . convertCase ( key , convertCaseOptions ) ] = this . convertCase ( value , convertCaseOptions ) ;
195+ result [ this . _convertCase ( key , convertCaseOptions ) ] = this . _convertCase ( value , convertCaseOptions ) ;
196196 } else {
197- result [ this . convertCase ( key , convertCaseOptions ) ] = value ;
197+ result [ this . _convertCase ( key , convertCaseOptions ) ] = value ;
198198 }
199199 } ) ;
200200 } else {
@@ -208,9 +208,7 @@ module.exports = class JSONAPISerializer {
208208 case 'camelCase' :
209209 converted = _ . camelCase ( data ) ;
210210 break ;
211- default :
212- converted = data ;
213- break ;
211+ default : // Do nothing
214212 }
215213 }
216214
0 commit comments