@@ -6,23 +6,26 @@ schemaKeys.push('definitions');
66
77module . exports = function addModel ( schema ) {
88 var modelSchema = _ . cloneDeep ( _ . pick ( schema , schemaKeys ) ) ;
9- stripSpecificProperties ( modelSchema ) ;
9+ filterProperties ( modelSchema . properties ) ;
10+ if ( modelSchema . definitions ) {
11+ Object . keys ( modelSchema . definitions ) . forEach ( function ( definitionName ) {
12+ var definitionValue = modelSchema . definitions [ definitionName ] ;
13+ filterProperties ( definitionValue . properties ) ;
14+ } ) ;
15+ }
1016 swagger . common . addModel ( modelSchema , { validation : 'warn' } ) ;
1117} ;
1218
13- const propertiesToStrip = [ 'faker' , 'chance' ] ;
14- function stripSpecificProperties ( schema ) {
15- if ( _ . isArray ( schema ) ) {
16- schema . forEach ( function ( item ) {
17- stripSpecificProperties ( item ) ;
19+ function filterProperties ( properties ) {
20+ Object . keys ( properties ) . forEach ( function ( propertyName ) {
21+ var propertyValue = properties [ propertyName ] ;
22+ Object . keys ( propertyValue ) . forEach ( function ( key ) {
23+ if ( schemaKeys . indexOf ( key ) < 0 ) {
24+ delete propertyValue [ key ] ;
25+ }
26+ if ( key . toLowerCase ( ) === 'properties' ) {
27+ filterProperties ( propertyValue . properties ) ;
28+ }
1829 } ) ;
19- return ;
20- }
21- if ( ! _ . isObject ( schema ) ) {
22- return ;
23- }
24- propertiesToStrip . forEach ( function ( key ) {
25- delete schema [ key ] ;
2630 } ) ;
27- _ . valuesIn ( schema ) . forEach ( stripSpecificProperties ) ;
2831}
0 commit comments