diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 5002e1a05..ee8b003cc 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -77,8 +77,8 @@ sequence_shape_to_type = { } mapping_shapes = {SHAPE_MAPPING} -mapping_types = dict -mapping_shapes_to_type = {SHAPE_MAPPING: dict} +mapping_types = (Mapping) +mapping_shapes_to_type = {SHAPE_MAPPING: Mapping} multipart_not_installed_error = ( 'Form data requires "python-multipart" to be installed. \n' @@ -254,14 +254,10 @@ def is_scalar_mapping_field(field: ModelField) -> bool: if (field.shape in mapping_shapes) and not lenient_issubclass( field.type_, BaseModel ): - if field.sub_fields is None: - return True for sub_field in field.sub_fields: if not is_scalar_field(sub_field): return False return True - if lenient_issubclass(field.type_, mapping_types): - return True return False @@ -269,14 +265,10 @@ def is_scalar_sequence_mapping_field(field: ModelField) -> bool: if (field.shape in mapping_shapes) and not lenient_issubclass( field.type_, BaseModel ): - if field.sub_fields is None: - return True for sub_field in field.sub_fields: if not is_scalar_sequence_field(sub_field): return False return True - if lenient_issubclass(field.type_, mapping_types): - return True return False diff --git a/tests/main.py b/tests/main.py index 21f0035f5..6040a53b5 100644 --- a/tests/main.py +++ b/tests/main.py @@ -190,13 +190,13 @@ def get_query_param_required_type(query: int = Query()): @app.get("/query/params") -def get_query_params(queries: Mapping[str, int] = Query({})): - return f"foo bar {queries}" +def get_query_params(query: Mapping[str, int] = Query({})): + return f"foo bar {query}" @app.get("/query/sequence-params") -def get_sequence_query_params(queries: Mapping[str, List[int]] = Query({})): - return f"foo bar {queries}" +def get_sequence_query_params(query: Mapping[str, List[int]] = Query({})): + return f"foo bar {query}" @app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED) diff --git a/tests/test_application.py b/tests/test_application.py index 7bd54f0c4..9363e1280 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -1086,12 +1086,12 @@ openapi_schema = { { "required": False, "schema": { - "title": "Queries", + "title": "Query", "type": "object", "additionalProperties": {"type": "integer"}, "default": {}, }, - "name": "queries", + "name": "query", "in": "query", } ], @@ -1119,7 +1119,7 @@ openapi_schema = { "parameters": [ { "in": "query", - "name": "queries", + "name": "query", "required": False, "schema": { "additionalProperties": { @@ -1127,7 +1127,7 @@ openapi_schema = { "type": "array", }, "default": {}, - "title": "Queries", + "title": "Query", "type": "object", }, } diff --git a/tests/test_query.py b/tests/test_query.py index 6fbca4d2c..3e0544bb2 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -63,7 +63,7 @@ response_not_valid_int = { "/query/sequence-params?first-query=1&first-query=2", 200, "foo bar {'first-query': [1, 2]}", - ), + ) ], ) def test_get_path(path, expected_status, expected_response):