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_shapes = {SHAPE_MAPPING}
|
||||||
mapping_types = dict
|
mapping_types = (Mapping)
|
||||||
mapping_shapes_to_type = {SHAPE_MAPPING: dict}
|
mapping_shapes_to_type = {SHAPE_MAPPING: Mapping}
|
||||||
|
|
||||||
multipart_not_installed_error = (
|
multipart_not_installed_error = (
|
||||||
'Form data requires "python-multipart" to be installed. \n'
|
'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(
|
if (field.shape in mapping_shapes) and not lenient_issubclass(
|
||||||
field.type_, BaseModel
|
field.type_, BaseModel
|
||||||
):
|
):
|
||||||
if field.sub_fields is None:
|
|
||||||
return True
|
|
||||||
for sub_field in field.sub_fields:
|
for sub_field in field.sub_fields:
|
||||||
if not is_scalar_field(sub_field):
|
if not is_scalar_field(sub_field):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
if lenient_issubclass(field.type_, mapping_types):
|
|
||||||
return True
|
|
||||||
return False
|
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(
|
if (field.shape in mapping_shapes) and not lenient_issubclass(
|
||||||
field.type_, BaseModel
|
field.type_, BaseModel
|
||||||
):
|
):
|
||||||
if field.sub_fields is None:
|
|
||||||
return True
|
|
||||||
for sub_field in field.sub_fields:
|
for sub_field in field.sub_fields:
|
||||||
if not is_scalar_sequence_field(sub_field):
|
if not is_scalar_sequence_field(sub_field):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
if lenient_issubclass(field.type_, mapping_types):
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,13 +190,13 @@ def get_query_param_required_type(query: int = Query()):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/query/params")
|
@app.get("/query/params")
|
||||||
def get_query_params(queries: Mapping[str, int] = Query({})):
|
def get_query_params(query: Mapping[str, int] = Query({})):
|
||||||
return f"foo bar {queries}"
|
return f"foo bar {query}"
|
||||||
|
|
||||||
|
|
||||||
@app.get("/query/sequence-params")
|
@app.get("/query/sequence-params")
|
||||||
def get_sequence_query_params(queries: Mapping[str, List[int]] = Query({})):
|
def get_sequence_query_params(query: Mapping[str, List[int]] = Query({})):
|
||||||
return f"foo bar {queries}"
|
return f"foo bar {query}"
|
||||||
|
|
||||||
|
|
||||||
@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED)
|
@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED)
|
||||||
|
|
|
||||||
|
|
@ -1086,12 +1086,12 @@ openapi_schema = {
|
||||||
{
|
{
|
||||||
"required": False,
|
"required": False,
|
||||||
"schema": {
|
"schema": {
|
||||||
"title": "Queries",
|
"title": "Query",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {"type": "integer"},
|
"additionalProperties": {"type": "integer"},
|
||||||
"default": {},
|
"default": {},
|
||||||
},
|
},
|
||||||
"name": "queries",
|
"name": "query",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -1119,7 +1119,7 @@ openapi_schema = {
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"name": "queries",
|
"name": "query",
|
||||||
"required": False,
|
"required": False,
|
||||||
"schema": {
|
"schema": {
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
|
|
@ -1127,7 +1127,7 @@ openapi_schema = {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
},
|
},
|
||||||
"default": {},
|
"default": {},
|
||||||
"title": "Queries",
|
"title": "Query",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ response_not_valid_int = {
|
||||||
"/query/sequence-params?first-query=1&first-query=2",
|
"/query/sequence-params?first-query=1&first-query=2",
|
||||||
200,
|
200,
|
||||||
"foo bar {'first-query': [1, 2]}",
|
"foo bar {'first-query': [1, 2]}",
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_path(path, expected_status, expected_response):
|
def test_get_path(path, expected_status, expected_response):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue