From cab74e7acda7e3d8fc89cf11b88af48648d37848 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 5 Nov 2019 14:58:40 +0100 Subject: [PATCH] misc: adapt payload when parsing JSON request body (#37490) --- passerelle/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/passerelle/views.py b/passerelle/views.py index fa0490a1..b90e47e3 100644 --- a/passerelle/views.py +++ b/passerelle/views.py @@ -46,6 +46,7 @@ from jsonschema import validate, ValidationError from passerelle.base.models import BaseResource, ResourceLog from passerelle.utils.jsonresponse import APIError +from passerelle.utils.json import unflatten from .utils import to_json, is_authorized from .forms import GenericConnectorForm @@ -340,10 +341,16 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View): request_body = self.endpoint.endpoint_info.post.get('request_body') if 'application/json' in request_body.get('schema', {}): json_schema = request_body['schema']['application/json'] + must_unflatten = hasattr(json_schema, 'items') and json_schema.get('unflatten', False) + merge_extra = hasattr(json_schema, 'items') and json_schema.get('merge_extra', False) try: data = json.loads(request.body) except ValueError as e: raise APIError("could not decode body to json: %s" % e, http_status=400) + if must_unflatten: + data = unflatten(data) + if merge_extra and hasattr(data, 'items'): + data.update(data.pop('extra', {})) try: validate(data, json_schema) except ValidationError as e: -- 2.23.0