mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
e3125fd1ed
commit
6bd8a838b0
|
|
@ -274,8 +274,7 @@ if PYDANTIC_V2:
|
|||
*, fields: Sequence[ModelField], model_name: str
|
||||
) -> Type[BaseModel]:
|
||||
field_params = {
|
||||
f"{f.alias}": (f.field_info.annotation, f.field_info)
|
||||
for f in fields
|
||||
f"{f.alias}": (f.field_info.annotation, f.field_info) for f in fields
|
||||
}
|
||||
BodyModel: Type[BaseModel] = create_model(model_name, **field_params) # type: ignore[call-overload]
|
||||
return BodyModel
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from starlette.testclient import TestClient
|
||||
|
||||
from fastapi import FastAPI, Form
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
app: FastAPI = FastAPI()
|
||||
|
||||
|
|
@ -9,6 +8,7 @@ app: FastAPI = FastAPI()
|
|||
async def check_alias(id_test: int = Form(alias="otherId")):
|
||||
return {"other_id": id_test}
|
||||
|
||||
|
||||
@app.post("/testing_validation_alias")
|
||||
async def check_validation_alias(id_test: int = Form(validation_alias="otherId")):
|
||||
return {"other_id": id_test}
|
||||
|
|
@ -22,11 +22,13 @@ def test_get_alias():
|
|||
assert response.status_code == 200
|
||||
assert response.json() == {"other_id": 1}
|
||||
|
||||
|
||||
def test_get_validation_alias():
|
||||
response = client.post("/testing_validation_alias", data={"otherId": "1"})
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"other_id": 1}
|
||||
|
||||
|
||||
def test_file_alias_schema():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200, response.text
|
||||
|
|
@ -41,7 +43,7 @@ def test_file_alias_schema():
|
|||
|
||||
assert (
|
||||
"otherId"
|
||||
in schema["components"]["schemas"]["Body_check_validation_alias_testing_validation_alias_post"][
|
||||
"properties"
|
||||
]
|
||||
in schema["components"]["schemas"][
|
||||
"Body_check_validation_alias_testing_validation_alias_post"
|
||||
]["properties"]
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue