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

✨ Add support for FrozenSet in parameters (e.g. query) #2938

Merged
merged 2 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions fastapi/dependencies/utils.py
Expand Up @@ -33,6 +33,7 @@
from pydantic.error_wrappers import ErrorWrapper
from pydantic.errors import MissingError
from pydantic.fields import (
SHAPE_FROZENSET,
SHAPE_LIST,
SHAPE_SEQUENCE,
SHAPE_SET,
Expand All @@ -56,6 +57,7 @@
sequence_shapes = {
SHAPE_LIST,
SHAPE_SET,
SHAPE_FROZENSET,
SHAPE_TUPLE,
SHAPE_SEQUENCE,
SHAPE_TUPLE_ELLIPSIS,
Expand Down
7 changes: 6 additions & 1 deletion tests/main.py
@@ -1,5 +1,5 @@
import http
from typing import Optional
from typing import FrozenSet, Optional

from fastapi import FastAPI, Path, Query

Expand Down Expand Up @@ -192,3 +192,8 @@ def get_query_param_required_type(query: int = Query(...)):
@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED)
def get_enum_status_code():
return "foo bar"


@app.get("/query/frozenset")
def get_query_type_frozenset(query: FrozenSet[int] = Query(...)):
return ",".join(map(str, sorted(query)))
35 changes: 35 additions & 0 deletions tests/test_application.py
Expand Up @@ -1090,6 +1090,41 @@
"operationId": "get_enum_status_code_enum_status_code_get",
}
},
"/query/frozenset": {
"get": {
"summary": "Get Query Type Frozenset",
"operationId": "get_query_type_frozenset_query_frozenset_get",
"parameters": [
{
"required": True,
"schema": {
"title": "Query",
"uniqueItems": True,
"type": "array",
"items": {"type": "integer"},
},
"name": "query",
"in": "query",
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
}
},
},
"components": {
"schemas": {
Expand Down
1 change: 1 addition & 0 deletions tests/test_query.py
Expand Up @@ -53,6 +53,7 @@
("/query/param-required/int", 422, response_missing),
("/query/param-required/int?query=50", 200, "foo bar 50"),
("/query/param-required/int?query=foo", 422, response_not_valid_int),
("/query/frozenset/?query=1&query=1&query=2", 200, "1,2"),
],
)
def test_get_path(path, expected_status, expected_response):
Expand Down