@@ -106,7 +106,7 @@ def _process(self):
106106 yield Schema (build_data (self .swagger ))
107107
108108
109- def merge_default (schema , value ):
109+ def merge_default (schema , value , get_first = True ):
110110 # TODO: more types support
111111 type_defaults = {
112112 'integer' : 9573 ,
@@ -116,7 +116,10 @@ def merge_default(schema, value):
116116 'boolean' : False
117117 }
118118
119- return normalize (schema , value , type_defaults )[0 ]
119+ results = normalize (schema , value , type_defaults )
120+ if get_first :
121+ return results [0 ]
122+ return results
120123
121124
122125def build_default (schema ):
@@ -172,10 +175,6 @@ def _normalize_dict(schema, data):
172175 for key , _schema in schema .get ('properties' , {}).iteritems ():
173176 # set default
174177 type_ = _schema .get ('type' , 'object' )
175- if ('default' not in _schema
176- and key in schema .get ('required' , [])
177- and type_ in required_defaults ):
178- _schema ['default' ] = required_defaults [type_ ]
179178
180179 # get value
181180 value , has_key = data .get_check (key )
@@ -184,8 +183,11 @@ def _normalize_dict(schema, data):
184183 elif 'default' in _schema :
185184 result [key ] = _schema ['default' ]
186185 elif key in schema .get ('required' , []):
187- errors .append (dict (name = 'property_missing' ,
188- message = '`%s` is required' % key ))
186+ if type_ in required_defaults :
187+ result [key ] = required_defaults [type_ ]
188+ else :
189+ errors .append (dict (name = 'property_missing' ,
190+ message = '`%s` is required' % key ))
189191
190192 for _schema in schema .get ('allOf' , []):
191193 rs_component = _normalize (_schema , data )
0 commit comments