mirror of https://github.com/tiangolo/fastapi.git
Copy alias to validation_alias
This commit is contained in:
parent
46d1da08da
commit
19e819d8a9
|
|
@ -560,6 +560,12 @@ class Body(FieldInfo):
|
|||
)
|
||||
current_json_schema_extra = json_schema_extra or extra
|
||||
if PYDANTIC_V2:
|
||||
if serialization_alias in (_Unset, None) and isinstance(alias, str):
|
||||
serialization_alias = alias
|
||||
|
||||
if validation_alias in (_Unset, None):
|
||||
validation_alias = alias
|
||||
|
||||
kwargs.update(
|
||||
{
|
||||
"annotation": annotation,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
from fastapi import FastAPI, Form
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.post("/")
|
||||
def route_with_form(form_param: str = Form(alias="aliased-field")):
|
||||
return {}
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_get_route():
|
||||
response = client.post("/", data={"aliased-field": "Hello, World!"})
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {}
|
||||
|
||||
|
||||
def test_openapi():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200, response.text
|
||||
form_properties = (
|
||||
response.json()
|
||||
["components"]["schemas"]["Body_route_with_form__post"]["properties"]
|
||||
)
|
||||
assert "aliased-field" in form_properties
|
||||
Loading…
Reference in New Issue