This commit is contained in:
JONEMI19 2024-02-29 09:28:47 +00:00
parent cec06df864
commit 84f9c634e1
4 changed files with 13 additions and 18 deletions

View File

@ -17,7 +17,7 @@ from typing import (
)
from fastapi.exceptions import RequestErrorModel
from fastapi.types import FFQuery, IncEx, ModelNameMap, UnionType
from fastapi.types import IncEx, ModelNameMap, UnionType
from pydantic import BaseModel, create_model
from pydantic.version import VERSION as PYDANTIC_VERSION
from starlette.datastructures import UploadFile
@ -43,7 +43,8 @@ sequence_annotation_to_type = {
sequence_types = tuple(sequence_annotation_to_type.keys())
mapping_annotation_to_type = {
FFQuery: list,
Dict: list,
dict: list,
}
mapping_types = tuple(mapping_annotation_to_type.keys())
@ -366,7 +367,7 @@ else:
mapping_shapes = {
SHAPE_MAPPING,
}
mapping_shapes_to_type = {SHAPE_MAPPING: FFQuery}
mapping_shapes_to_type = {SHAPE_MAPPING: Dict}
@dataclass
class GenerateJsonSchema: # type: ignore[no-redef]

View File

@ -8,7 +8,3 @@ DecoratedCallable = TypeVar("DecoratedCallable", bound=Callable[..., Any])
UnionType = getattr(types, "UnionType", Union)
ModelNameMap = Dict[Union[Type[BaseModel], Type[Enum]], str]
IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]
class FFQuery(Dict[str, Union[str, IncEx]]):
pass

View File

@ -1,8 +1,7 @@
import http
from typing import FrozenSet, List, Optional, Union
from typing import FrozenSet, List, Optional, Union, Dict
from fastapi import FastAPI, Path, Query
from fastapi.types import FFQuery
app = FastAPI()
@ -186,19 +185,19 @@ def get_query_param_required_type(query: int = Query()):
@app.get("/query/mapping-params")
def get_mapping_query_params(queries: FFQuery[str, str] = Query({})):
def get_mapping_query_params(queries: Dict[str, str] = Query({})):
return f"foo bar {queries['foo']} {queries['bar']}"
@app.get("/query/mapping-sequence-params")
def get_sequence_mapping_query_params(queries: FFQuery[str, List[int]] = Query({})):
def get_sequence_mapping_query_params(queries: Dict[str, List[int]] = Query({})):
return f"foo bar {dict(queries)}"
@app.get("/query/mixed-params")
def get_mixed_mapping_query_params(
sequence_mapping_queries: FFQuery[str, List[Union[str, int]]] = Query({}),
mapping_query: FFQuery[str, str] = Query(),
sequence_mapping_queries: Dict[str, List[Union[str, int]]] = Query({}),
mapping_query: Dict[str, str] = Query(),
query: str = Query(),
):
return (
@ -209,9 +208,9 @@ def get_mixed_mapping_query_params(
@app.get("/query/mixed-type-params")
def get_mixed_mapping_mixed_type_query_params(
sequence_mapping_queries: FFQuery[str, List[int]] = Query({}),
mapping_query_str: FFQuery[str, str] = Query({}),
mapping_query_int: FFQuery[str, int] = Query({}),
sequence_mapping_queries: Dict[str, List[int]] = Query({}),
mapping_query_str: Dict[str, str] = Query({}),
mapping_query_int: Dict[str, int] = Query({}),
query: int = Query(),
):
return f"foo bar {query} {mapping_query_str} {mapping_query_int} {dict(sequence_mapping_queries)}"

View File

@ -2,7 +2,6 @@ from typing import List
import pytest
from fastapi import FastAPI, Query
from fastapi.types import FFQuery
def test_invalid_sequence():
@ -10,5 +9,5 @@ def test_invalid_sequence():
app = FastAPI()
@app.get("/items/")
def read_items(q: FFQuery[str, List[List[str]]] = Query(default=None)):
def read_items(q: Dict[str, List[List[str]]] = Query(default=None)):
pass # pragma: no cover