0004-misc-adapt-payload-when-parsing-JSON-request-body-35.patch
passerelle/views.py | ||
---|---|---|
46 | 46 | |
47 | 47 |
from passerelle.base.models import BaseResource, ResourceLog |
48 | 48 |
from passerelle.utils.jsonresponse import APIError |
49 |
from passerelle.utils.json import unflatten |
|
49 | 50 | |
50 | 51 |
from .utils import to_json, is_authorized |
51 | 52 |
from .forms import GenericConnectorForm |
... | ... | |
340 | 341 |
request_body = self.endpoint.endpoint_info.post.get('request_body', {}) |
341 | 342 |
if 'application/json' in request_body.get('schema', {}): |
342 | 343 |
json_schema = request_body['schema']['application/json'] |
344 |
must_unflatten = hasattr(json_schema, 'items') and json_schema.get('unflatten', False) |
|
345 |
merge_extra = hasattr(json_schema, 'items') and json_schema.get('merge_extra', False) |
|
343 | 346 |
try: |
344 | 347 |
data = json.loads(request.body) |
345 | 348 |
except ValueError as e: |
346 | 349 |
raise APIError("could not decode body to json: %s" % e, http_status=400) |
350 |
if must_unflatten: |
|
351 |
data = unflatten(data) |
|
352 |
if merge_extra and hasattr(data, 'items'): |
|
353 |
data.update(data.pop('extra', {})) |
|
347 | 354 |
try: |
348 | 355 |
validate(data, json_schema) |
349 | 356 |
except ValidationError as e: |
350 |
- |