|
|
|
@ -75,11 +75,15 @@ def test_required_dict_str(path: str): |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.json() == {"p": {"foo": "bar", "baz": "qux"}} |
|
|
|
|
|
|
|
|
|
|
|
# ===================================================================================== |
|
|
|
# With union types |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/required-dict-union") |
|
|
|
async def read_required_dict_union(p: Annotated[dict[str, str] | dict[str, int], Query()]): |
|
|
|
async def read_required_dict_union( |
|
|
|
p: Annotated[dict[str, str] | dict[str, int], Query()], |
|
|
|
): |
|
|
|
return {"p": p} |
|
|
|
|
|
|
|
|
|
|
|
@ -91,6 +95,7 @@ class QueryModelRequiredDictUnion(BaseModel): |
|
|
|
def read_model_required_dict_union(p: Annotated[QueryModelRequiredDictUnion, Query()]): |
|
|
|
return {"p": p.p} |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-union", "/model-required-dict-union"], |
|
|
|
@ -117,6 +122,7 @@ def test_required_dict_union_schema(path: str): |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-union", "/model-required-dict-union"], |
|
|
|
@ -136,6 +142,7 @@ def test_required_dict_union_missing(path: str): |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-union", "/model-required-dict-union"], |
|
|
|
@ -146,6 +153,7 @@ def test_required_dict_union(path: str): |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.json() == {"p": {"foo": "bar", "baz": "42"}} |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/required-dict-of-union") |
|
|
|
async def read_required_dict_of_union(p: Annotated[dict[str, int | bool], Query()]): |
|
|
|
return {"p": p} |
|
|
|
@ -161,6 +169,7 @@ def read_model_required_dict_of_union( |
|
|
|
): |
|
|
|
return {"p": p.p} |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-of-union", "/model-required-dict-of-union"], |
|
|
|
@ -184,6 +193,7 @@ def test_required_dict_of_union_schema(path: str): |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-of-union", "/model-required-dict-of-union"], |
|
|
|
@ -215,19 +225,23 @@ def test_required_dict_of_union(path: str): |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.json() == {"p": {"foo": True, "baz": 42}} |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/required-dict-of-list") |
|
|
|
async def read_required_dict_of_list(p: Annotated[dict[str, list[int]], Query()]): |
|
|
|
return {"p": p} |
|
|
|
|
|
|
|
|
|
|
|
class QueryModelRequiredDictOfList(BaseModel): |
|
|
|
p: dict[str, list[int]] |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/model-required-dict-of-list") |
|
|
|
def read_model_required_dict_of_list( |
|
|
|
p: Annotated[QueryModelRequiredDictOfList, Query()], |
|
|
|
): |
|
|
|
return {"p": p.p} |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-of-list", "/model-required-dict-of-list"], |
|
|
|
@ -249,6 +263,7 @@ def test_required_dict_of_list_schema(path: str): |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-of-list", "/model-required-dict-of-list"], |
|
|
|
@ -268,6 +283,7 @@ def test_required_dict_of_list_missing(path: str): |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"path", |
|
|
|
["/required-dict-of-list", "/model-required-dict-of-list"], |
|
|
|
|