Skip to content

Commit

Permalink
✨ Add support for FrozenSet in parameters (e.g. query) (#2938)
Browse files Browse the repository at this point in the history
Co-authored-by: saborisov <borisov_s@tass.ru>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
  • Loading branch information
3 people committed Aug 25, 2022
1 parent af3a6ef commit ca2fae0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fastapi/dependencies/utils.py
Expand Up @@ -34,6 +34,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 @@ -58,6 +59,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

0 comments on commit ca2fae0

Please sign in to comment.