Skip to content

Falcon multi-value query parameters fix #830

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

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
3 changes: 2 additions & 1 deletion openapi_core/contrib/falcon/requests.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
from werkzeug.datastructures import Headers
from werkzeug.datastructures import ImmutableMultiDict

from openapi_core.contrib.falcon.util import unpack_params
from openapi_core.datatypes import RequestParameters


@@ -29,7 +30,7 @@ def __init__(

# Path gets deduced by path finder against spec
self.parameters = RequestParameters(
query=ImmutableMultiDict(list(self.request.params.items())),
query=ImmutableMultiDict(unpack_params(self.request.params)),
header=Headers(self.request.headers),
cookie=self.request.cookies,
)
15 changes: 15 additions & 0 deletions openapi_core/contrib/falcon/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any
from typing import Dict
from typing import Generator
from typing import Tuple


def unpack_params(
params: Dict[str, Any]
) -> Generator[Tuple[str, Any], None, None]:
for k, v in params.items():
if isinstance(v, list):
for v2 in v:
yield (k, v2)
else:
yield (k, v)
Original file line number Diff line number Diff line change
@@ -11,11 +11,19 @@ class PetListResource:
def on_get(self, request, response):
assert request.context.openapi
assert not request.context.openapi.errors
assert request.context.openapi.parameters.query == {
"page": 1,
"limit": 12,
"search": "",
}
if "ids" in request.params:
assert request.context.openapi.parameters.query == {
"page": 1,
"limit": 2,
"search": "",
"ids": [1, 2],
}
else:
assert request.context.openapi.parameters.query == {
"page": 1,
"limit": 12,
"search": "",
}
data = [
{
"id": 12,
27 changes: 27 additions & 0 deletions tests/integration/contrib/falcon/test_falcon_project.py
Original file line number Diff line number Diff line change
@@ -67,6 +67,33 @@ def test_get_valid(self, client):
],
}

def test_get_valid_multiple_ids(self, client):
headers = {
"Content-Type": "application/json",
}
query_string = "limit=2&ids=1&ids=2"

with pytest.warns(DeprecationWarning):
response = client.simulate_get(
"/v1/pets",
host="petstore.swagger.io",
headers=headers,
query_string=query_string,
)

assert response.status_code == 200
assert response.json == {
"data": [
{
"id": 12,
"name": "Cat",
"ears": {
"healthy": True,
},
},
],
}

def test_post_server_invalid(self, client):
response = client.simulate_post(
"/v1/pets",