mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
ec60f7dfb8
commit
0dacaa63be
|
|
@ -262,7 +262,10 @@ if PYDANTIC_V2:
|
|||
def create_body_model(
|
||||
*, fields: Sequence[ModelField], model_name: str
|
||||
) -> Type[BaseModel]:
|
||||
field_params = {f"{f.field_info.alias}": (f.field_info.annotation, f.field_info) for f in fields}
|
||||
field_params = {
|
||||
f"{f.field_info.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
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,17 @@ app: FastAPI = FastAPI()
|
|||
|
||||
@app.post("/testing_alias")
|
||||
async def check_alias(id_test: int = Form(alias="otherId")):
|
||||
return {"other_id":id_test}
|
||||
return {"other_id": id_test}
|
||||
|
||||
|
||||
@app.patch("/testing")
|
||||
async def check_without_alias(id_test:int = Form()):
|
||||
return {"id_test":id_test}
|
||||
async def check_without_alias(id_test: int = Form()):
|
||||
return {"id_test": id_test}
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_without_alias():
|
||||
response = client.patch("/testing", data={"id_test": 1})
|
||||
assert response.status_code == 200
|
||||
|
|
@ -23,4 +26,4 @@ def test_without_alias():
|
|||
def test_get_alias():
|
||||
response = client.post("/testing_alias", data={"otherId": "1"})
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"other_id": 1}
|
||||
assert response.json() == {"other_id": 1}
|
||||
|
|
|
|||
Loading…
Reference in New Issue