From 2bba8d0d0bbf2e48a795ef101334a23fb565059c Mon Sep 17 00:00:00 2001 From: HYChang Date: Mon, 8 Jul 2024 16:55:11 +0800 Subject: [PATCH] Add array support for reqparser Add missing items for type array. --- flask_restx/reqparse.py | 3 +++ flask_restx/swagger.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/flask_restx/reqparse.py b/flask_restx/reqparse.py index 8461f0ec..6bce216d 100644 --- a/flask_restx/reqparse.py +++ b/flask_restx/reqparse.py @@ -11,6 +11,7 @@ from werkzeug import exceptions from .errors import abort, SpecsError +from .fields import List from .marshalling import marshal from .model import Model from ._http import HTTPStatus @@ -167,6 +168,8 @@ def convert(self, value, op): elif isinstance(self.type, Model) and isinstance(value, dict): return marshal(value, self.type) + elif isinstance(self.type, List) and isinstance(value, list): + return value # and check if we're expecting a filestorage and haven't overridden `type` # (required because the below instantiation isn't valid for FileStorage) diff --git a/flask_restx/swagger.py b/flask_restx/swagger.py index ec0a1975..17ba9ffe 100644 --- a/flask_restx/swagger.py +++ b/flask_restx/swagger.py @@ -214,7 +214,11 @@ def build_request_body_parameters_schema(body_params): properties = {} for param in body_params: - properties[param["name"]] = {"type": param.get("type", "string")} + ptype = param.get("type", "string") + if ptype == "array": + properties[param["name"]] = {"type": "array", "items": param.get("type", "string")} + else: + properties[param["name"]] = {"type": param.get("type", "string")} return { "name": "payload",