1+ var isObject = require ( '../utils/isObject' ) . isObject ;
12var InvalidTypeError = require ( '../errors/invalid-type-error' ) ;
23
34module . exports = convertFromSchema ;
@@ -24,14 +25,22 @@ function convertSchema(schema, options) {
2425
2526 if ( Array . isArray ( schema [ struct ] ) ) {
2627 for ( j ; j < schema [ struct ] . length ; j ++ ) {
28+ if ( ! isObject ( schema [ struct ] [ j ] ) ) {
29+ schema [ struct ] . splice ( j , 1 ) ;
30+ j -- ;
31+ continue ;
32+ }
33+
2734 schema [ struct ] [ j ] = convertSchema ( schema [ struct ] [ j ] , options ) ;
2835 }
36+ } else if ( schema [ struct ] === null ) {
37+ delete schema [ struct ] ;
2938 } else if ( typeof schema [ struct ] === 'object' ) {
3039 schema [ struct ] = convertSchema ( schema [ struct ] , options ) ;
3140 }
3241 }
3342
34- if ( typeof schema . properties === 'object' ) {
43+ if ( ' properties' in schema ) {
3544 schema . properties = convertProperties ( schema . properties , options ) ;
3645
3746 if ( Array . isArray ( schema . required ) ) {
@@ -44,15 +53,13 @@ function convertSchema(schema, options) {
4453 if ( Object . keys ( schema . properties ) . length === 0 ) {
4554 delete schema . properties ;
4655 }
47-
4856 }
4957
5058 validateType ( schema . type ) ;
5159 schema = convertTypes ( schema ) ;
5260 schema = convertFormat ( schema , options ) ;
5361
54- if ( typeof schema [ 'x-patternProperties' ] === 'object'
55- && options . supportPatternProperties ) {
62+ if ( 'x-patternProperties' in schema && options . supportPatternProperties ) {
5663 schema = convertPatternProperties ( schema , options . patternPropertiesHandler ) ;
5764 }
5865
@@ -78,10 +85,18 @@ function convertProperties(properties, options) {
7885 , removeProp
7986 ;
8087
88+ if ( ! isObject ( properties ) ) {
89+ return props ;
90+ }
91+
8192 for ( key in properties ) {
8293 removeProp = false ;
8394 property = properties [ key ] ;
8495
96+ if ( ! isObject ( property ) ) {
97+ continue ;
98+ }
99+
85100 options . _removeProps . forEach ( function ( prop ) {
86101 if ( property [ prop ] === true ) {
87102 removeProp = true ;
@@ -189,7 +204,10 @@ function convertFormatByte (schema, settings) {
189204}
190205
191206function convertPatternProperties ( schema , handler ) {
192- schema . patternProperties = schema [ 'x-patternProperties' ] ;
207+ if ( isObject ( schema [ 'x-patternProperties' ] ) ) {
208+ schema . patternProperties = schema [ 'x-patternProperties' ] ;
209+ }
210+
193211 delete schema [ 'x-patternProperties' ] ;
194212
195213 return handler ( schema ) ;
0 commit comments