Fix a bug with no API validation being performed if user provided no
request body for API endpoints where body is mandatory (e.g. POST, PUT).
@@ -343,10 +343,15 @@ class Router(object):
elif source == 'request':
kw[argument_name] = getattr(req, name)
elif source == 'body':
- if req.body:
+ # Note: We also want to perform validation if no body is explicitly provided - in a
+ # lot of POST, PUT scenarios, body is mandatory
+ if not req.body:
+ req.body = '{}'
+
content_type = req.headers.get('Content-Type', 'application/json')
content_type = parse_content_type_header(content_type=content_type)[0]
schema = param['schema']
+ print content_type
try:
if content_type == 'application/json':
@@ -382,7 +387,10 @@ class Router(object):
if 'x-api-model' in schema:
Model = op_resolver(schema['x-api-model'])
+ print 'xxx'
+ print data
instance = Model(**data)
+ print instance
# Call validate on the API model - note we should eventually move all
# those model schema definitions into openapi.yaml
@@ -398,8 +406,8 @@ class Router(object):
instance = model(**data)
kw[argument_name] = instance
- else:
- kw[argument_name] = None
+ #else:
+ # kw[argument_name] = None
# Making sure all required params are present
required = param.get('required', False)
