]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Tweak intro docs about `Annotated` and `Query()` params (#11664)
authorSebastián Ramírez <tiangolo@gmail.com>
Fri, 31 May 2024 02:38:05 +0000 (21:38 -0500)
committerGitHub <noreply@github.com>
Fri, 31 May 2024 02:38:05 +0000 (21:38 -0500)
docs/en/docs/python-types.md
docs/en/docs/tutorial/query-params-str-validations.md

index 3e8267aea0822d955a668cd1d69f1cd0d803550a..20ffcdccc74f0293cdaacd417f84d692f1b0e217 100644 (file)
@@ -476,7 +476,7 @@ You will see a lot more of all this in practice in the [Tutorial - User Guide](t
 
 ## Type Hints with Metadata Annotations
 
-Python also has a feature that allows putting **additional metadata** in these type hints using `Annotated`.
+Python also has a feature that allows putting **additional <abbr title="Data about the data, in this case, information about the type, e.g. a description.">metadata</abbr>** in these type hints using `Annotated`.
 
 === "Python 3.9+"
 
index 24784efadd0fb2897b1dd806ca6b71e9f5d98070..da8e53720afabe7361b54c5223527ba43cd1b3ed 100644 (file)
@@ -99,7 +99,7 @@ Now let's jump to the fun stuff. 🎉
 
 ## Add `Query` to `Annotated` in the `q` parameter
 
-Now that we have this `Annotated` where we can put more metadata, add `Query` to it, and set the parameter `max_length` to 50:
+Now that we have this `Annotated` where we can put more information (in this case some additional validation), add `Query` inside of `Annotated`, and set the parameter `max_length` to `50`:
 
 === "Python 3.10+"
 
@@ -115,7 +115,11 @@ Now that we have this `Annotated` where we can put more metadata, add `Query` to
 
 Notice that the default value is still `None`, so the parameter is still optional.
 
-But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to extract this value from the query parameters (this would have been the default anyway 🤷) and that we want to have **additional validation** for this value (that's why we do this, to get the additional validation). 😎
+But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to have **additional validation** for this value, we want it to have maximum 50 characters. 😎
+
+!!! tip
+
+    Here we are using `Query()` because this is a **query parameter**. Later we will see others like `Path()`, `Body()`, `Header()`, and `Cookie()`, that also accept the same arguments as `Query()`.
 
 FastAPI will now: