mirror of https://github.com/tiangolo/fastapi.git
adding tests and restricting mappings to only Mapping type
This commit is contained in:
parent
2fd29c1775
commit
4e15aa1d12
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue