File size: 1,508 Bytes
5a9e79d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
diff --git a/tests/test_annotated_aug.py b/tests/test_annotated_aug.py
new file mode 100644
index 0000000..f664daa
--- /dev/null
+++ b/tests/test_annotated_aug.py
@@ -0,0 +1,37 @@
+from fastapi import FastAPI
+from fastapi.params import File as FileParam
+from fastapi.params import Form as FormParam
+from fastapi.testclient import TestClient
+from typing_extensions import Annotated
+
+
+def test_annotated_form_without_positional_default():
+    app = FastAPI()
+
+    @app.post("/submit")
+    def submit(name: Annotated[str, FormParam()]):
+        return {"name": name}
+
+    client = TestClient(app)
+    response = client.post("/submit", data={"name": "Ada"})
+
+    assert response.status_code == 200
+    assert response.json() == {"name": "Ada"}
+
+
+def test_annotated_file_without_positional_default():
+    app = FastAPI()
+
+    @app.post("/upload")
+    async def upload(payload: Annotated[bytes, FileParam()]):
+        return {"size": len(payload)}
+
+    client = TestClient(app)
+    response = client.post("/upload", files={"payload": ("note.txt", b"hello")})
+
+    assert response.status_code == 200
+    assert response.json() == {"size": 5}
+
+
+def test_plain_query_parameter_default_still_works():
+    app = FastAPI()
+
+    @app.get("/items")
+    def read_items(q: str = "default"):
+        return {"q": q}
+
+    client = TestClient(app)
+    assert client.get("/items").json() == {"q": "default"}
+    assert client.get("/items", params={"q": "set"}).json() == {"q": "set"}