mirror of https://github.com/tiangolo/fastapi.git
✨ Add support for `FrozenSet` in parameters (e.g. query) (#2938)
Co-authored-by: saborisov <borisov_s@tass.ru> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
af3a6ef78b
commit
ca2fae0588
|
|
@ -34,6 +34,7 @@ from pydantic import BaseModel, create_model
|
|||
from pydantic.error_wrappers import ErrorWrapper
|
||||
from pydantic.errors import MissingError
|
||||
from pydantic.fields import (
|
||||
SHAPE_FROZENSET,
|
||||
SHAPE_LIST,
|
||||
SHAPE_SEQUENCE,
|
||||
SHAPE_SET,
|
||||
|
|
@ -58,6 +59,7 @@ from starlette.websockets import WebSocket
|
|||
sequence_shapes = {
|
||||
SHAPE_LIST,
|
||||
SHAPE_SET,
|
||||
SHAPE_FROZENSET,
|
||||
SHAPE_TUPLE,
|
||||
SHAPE_SEQUENCE,
|
||||
SHAPE_TUPLE_ELLIPSIS,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import http
|
||||
from typing import Optional
|
||||
from typing import FrozenSet, Optional
|
||||
|
||||
from fastapi import FastAPI, Path, Query
|
||||
|
||||
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -1090,6 +1090,41 @@ openapi_schema = {
|
|||
"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": {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ response_not_valid_int = {
|
|||
("/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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue