Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import logging
import sys
from urllib.parse import parse_qs

import six
from jsonschema import Draft4Validator, ValidationError, draft4_format_checker
Expand Down Expand Up @@ -106,6 +107,19 @@ def validate_formdata_parameter_list(self, request):
spec_params = self.schema.get('properties', {}).keys()
return validate_parameter_list(request_params, spec_params)

def parse_body_parameters(self, body, encoding="ascii"):
parsed_body = parse_qs(body.decode(encoding))
# Flatten the parameters and take only the first value
params = dict()
for key,value in parsed_body.items():
valen = len(value)
if valen:
if valen<=1:
params[key] = value[0] # flatten single element lists
else:
params[key] = value # leave multi-valued lists intact
return params

def __call__(self, function):
"""
:type function: types.FunctionType
Expand Down Expand Up @@ -143,7 +157,8 @@ def wrapper(request):
if error and not self.has_default:
return error
elif self.consumes[0] in FORM_CONTENT_TYPES:
data = dict(request.form.items()) or (request.body if len(request.body) > 0 else {})
data = dict(request.form.items()) or \
(self.parse_body_parameters(request.body) if len(request.body) > 0 else {})
data.update(dict.fromkeys(request.files, '')) # validator expects string..
logger.debug('%s validating schema...', request.url)

Expand Down
2 changes: 1 addition & 1 deletion connexion/operations/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def body_definition(self):
return {}

def _get_body_argument(self, body, arguments, has_kwargs, sanitize):
x_body_name = self.body_schema.get('x-body-name', 'body')
x_body_name = self.body_schema.get('x-body-name', 'request_body')
if is_nullable(self.body_schema) and is_null(body):
return {x_body_name: None}

Expand Down