Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 177 #542

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ Releases prior to 0.3.0 were “best effort” filled out, but are missing
some info. If you see your contribution missing info, please open a PR
on the Changelog!

.. _section-1.2.0:
1.2.0
-----
.. _bug_fixes-1.2.0
Bug Fixes
~~~~~~~~~

::

* Fixing issue #177 to allow file list uploads, whilst other arugments are present.

.. _section-1.1.0:
1.1.0
-----
Expand Down
3 changes: 3 additions & 0 deletions flask_restx/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ def serialize_operation(self, doc, method):
if all_params and any(p["in"] == "formData" for p in all_params):
if any(p["type"] == "file" for p in all_params):
operation["consumes"] = ["multipart/form-data"]
elif any(p["type"] == "array" and p["collectionFormat"] == "multi" for p in all_params
if "collectionFormat" in p):
operation["consumes"] = ["multipart/form-data"]
else:
operation["consumes"] = [
"application/x-www-form-urlencoded",
Expand Down
43 changes: 43 additions & 0 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,49 @@ def get(self):
assert "consumes" in op
assert op["consumes"] == ["multipart/form-data"]

def test_parser_parameter_in_files_append_only(self, api, client):
parser = api.parser()
parser.add_argument(
"in_files", type=FileStorage, location="files", action="append"
)

@api.route("/with-parser/", endpoint="with-parser")
class WithParserResource(restx.Resource):
@api.expect(parser)
def post(self):
return {}

data = client.get_specs()
assert "/with-parser/" in data["paths"]

path = data["paths"]["/with-parser/"]
op = path["post"]
assert op["consumes"][0] == "multipart/form-data"

def test_parser_parameter_in_files_append_multiple_parameters(self, api, client):
parser = api.parser()
parser.add_argument(
"in_files", type=FileStorage, location="files", action="append"
)
# Ensure that we have a second argument not of type file, and therefore will not have the collectionFormat
# attribute
parser.add_argument(
"arbitrary_arguments", type=str, location="form"
)

@api.route("/with-parser/", endpoint="with-parser")
class WithParserResource(restx.Resource):
@api.expect(parser)
def post(self):
return {}

data = client.get_specs()
assert "/with-parser/" in data["paths"]

path = data["paths"]["/with-parser/"]
op = path["post"]
assert op["consumes"][0] == "multipart/form-data"

def test_explicit_parameters(self, api, client):
@api.route("/name/<int:age>/", endpoint="by-name")
class ByNameResource(restx.Resource):
Expand Down