mirror of https://github.com/tiangolo/fastapi.git
📝 Tweak tip recommending `Annotated` in docs (#9270)
📝 Tweak tip recommending Annotated
This commit is contained in:
parent
fbfd53542e
commit
0bc87ec77c
|
|
@ -35,7 +35,7 @@ To achieve that, import `JSONResponse`, and return your content there directly,
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 23"
|
||||
{!> ../../../docs_src/additional_status_codes/tutorial001_py310.py!}
|
||||
|
|
@ -44,7 +44,7 @@ To achieve that, import `JSONResponse`, and return your content there directly,
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4 25"
|
||||
{!> ../../../docs_src/additional_status_codes/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ To do that, we declare a method `__call__`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/dependencies/tutorial011.py!}
|
||||
|
|
@ -60,7 +60,7 @@ And now, we can use `__init__` to declare the parameters of the instance that we
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/dependencies/tutorial011.py!}
|
||||
|
|
@ -87,7 +87,7 @@ We could create an instance of this class with:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="16"
|
||||
{!> ../../../docs_src/dependencies/tutorial011.py!}
|
||||
|
|
@ -122,7 +122,7 @@ checker(q="somequery")
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="20"
|
||||
{!> ../../../docs_src/dependencies/tutorial011.py!}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Then, when you type that username and password, the browser sends them in the he
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 6 10"
|
||||
{!> ../../../docs_src/security/tutorial006.py!}
|
||||
|
|
@ -74,7 +74,7 @@ Then we can use `secrets.compare_digest()` to ensure that `credentials.username`
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 11-21"
|
||||
{!> ../../../docs_src/security/tutorial007.py!}
|
||||
|
|
@ -157,7 +157,7 @@ After detecting that the credentials are incorrect, return an `HTTPException` wi
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="23-27"
|
||||
{!> ../../../docs_src/security/tutorial007.py!}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ First, let's quickly see the parts that change from the examples in the main **T
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 152"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -86,7 +86,7 @@ First, let's quickly see the parts that change from the examples in the main **T
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -95,7 +95,7 @@ First, let's quickly see the parts that change from the examples in the main **T
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -130,7 +130,7 @@ The `scopes` parameter receives a `dict` with each scope as a key and the descri
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="61-64"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -140,7 +140,7 @@ The `scopes` parameter receives a `dict` with each scope as a key and the descri
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="62-65"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -149,7 +149,7 @@ The `scopes` parameter receives a `dict` with each scope as a key and the descri
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="62-65"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -197,7 +197,7 @@ And we return the scopes as part of the JWT token.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="152"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -206,7 +206,7 @@ And we return the scopes as part of the JWT token.
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="153"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -215,7 +215,7 @@ And we return the scopes as part of the JWT token.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="153"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -263,7 +263,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3 138 165"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -272,7 +272,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4 139 166"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -281,7 +281,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4 139 166"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -329,7 +329,7 @@ This `SecurityScopes` class is similar to `Request` (`Request` was used to get t
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7 104"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -338,7 +338,7 @@ This `SecurityScopes` class is similar to `Request` (`Request` was used to get t
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8 105"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -347,7 +347,7 @@ This `SecurityScopes` class is similar to `Request` (`Request` was used to get t
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8 105"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -386,7 +386,7 @@ In this exception, we include the scopes required (if any) as a string separated
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="104 106-114"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -395,7 +395,7 @@ In this exception, we include the scopes required (if any) as a string separated
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="105 107-115"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -404,7 +404,7 @@ In this exception, we include the scopes required (if any) as a string separated
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="105 107-115"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -445,7 +445,7 @@ We also verify that we have a user with that username, and if not, we raise that
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="45 115-126"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -454,7 +454,7 @@ We also verify that we have a user with that username, and if not, we raise that
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="46 116-127"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -463,7 +463,7 @@ We also verify that we have a user with that username, and if not, we raise that
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="46 116-127"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
@ -496,7 +496,7 @@ For this, we use `security_scopes.scopes`, that contains a `list` with all these
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="127-133"
|
||||
{!> ../../../docs_src/security/tutorial005_py310.py!}
|
||||
|
|
@ -505,7 +505,7 @@ For this, we use `security_scopes.scopes`, that contains a `list` with all these
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="128-134"
|
||||
{!> ../../../docs_src/security/tutorial005_py39.py!}
|
||||
|
|
@ -514,7 +514,7 @@ For this, we use `security_scopes.scopes`, that contains a `list` with all these
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="128-134"
|
||||
{!> ../../../docs_src/security/tutorial005.py!}
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ Now we create a dependency that returns a new `config.Settings()`.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="5 11-12"
|
||||
{!> ../../../docs_src/settings/app02/main.py!}
|
||||
|
|
@ -259,7 +259,7 @@ And then we can require it from the *path operation function* as a dependency an
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="16 18-20"
|
||||
{!> ../../../docs_src/settings/app02/main.py!}
|
||||
|
|
@ -353,7 +353,7 @@ But as we are using the `@lru_cache()` decorator on top, the `Settings` object w
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 10"
|
||||
{!> ../../../docs_src/settings/app03/main.py!}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ And then **FastAPI** will call that override instead of the original dependency.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="24-25 28"
|
||||
{!> ../../../docs_src/dependency_testing/tutorial001_py310.py!}
|
||||
|
|
@ -58,7 +58,7 @@ And then **FastAPI** will call that override instead of the original dependency.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="28-29 32"
|
||||
{!> ../../../docs_src/dependency_testing/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ They work the same way as for other FastAPI endpoints/*path operations*:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="66-67 79"
|
||||
{!> ../../../docs_src/websockets/tutorial002_py310.py!}
|
||||
|
|
@ -142,7 +142,7 @@ They work the same way as for other FastAPI endpoints/*path operations*:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="68-69 81"
|
||||
{!> ../../../docs_src/websockets/tutorial002.py!}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ Using `BackgroundTasks` also works with the dependency injection system, you can
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11 13 20 23"
|
||||
{!> ../../../docs_src/background_tasks/tutorial002_py310.py!}
|
||||
|
|
@ -87,7 +87,7 @@ Using `BackgroundTasks` also works with the dependency injection system, you can
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="13 15 22 25"
|
||||
{!> ../../../docs_src/background_tasks/tutorial002.py!}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ We will now use a simple dependency to read a custom `X-Token` header:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 4-6"
|
||||
{!> ../../../docs_src/bigger_applications/app/dependencies.py!}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ First, you have to import it:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2"
|
||||
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
|
||||
|
|
@ -36,7 +36,7 @@ First, you have to import it:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4"
|
||||
{!> ../../../docs_src/body_fields/tutorial001.py!}
|
||||
|
|
@ -70,7 +70,7 @@ You can then use `Field` with model attributes:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9-12"
|
||||
{!> ../../../docs_src/body_fields/tutorial001_py310.py!}
|
||||
|
|
@ -79,7 +79,7 @@ You can then use `Field` with model attributes:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11-14"
|
||||
{!> ../../../docs_src/body_fields/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ And you can also declare body parameters as optional, by setting the default to
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17-19"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial001_py310.py!}
|
||||
|
|
@ -38,7 +38,7 @@ And you can also declare body parameters as optional, by setting the default to
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19-21"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial001.py!}
|
||||
|
|
@ -132,7 +132,7 @@ But you can instruct **FastAPI** to treat it as another body key using `Body`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="20"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial003_py310.py!}
|
||||
|
|
@ -141,7 +141,7 @@ But you can instruct **FastAPI** to treat it as another body key using `Body`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="22"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial003.py!}
|
||||
|
|
@ -206,7 +206,7 @@ For example:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="25"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004_py310.py!}
|
||||
|
|
@ -215,7 +215,7 @@ For example:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="27"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004.py!}
|
||||
|
|
@ -259,7 +259,7 @@ as in:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="15"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial005_py310.py!}
|
||||
|
|
@ -268,7 +268,7 @@ as in:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial005.py!}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ First import `Cookie`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
|
||||
|
|
@ -36,7 +36,7 @@ First import `Cookie`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001.py!}
|
||||
|
|
@ -69,7 +69,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
|
||||
|
|
@ -78,7 +78,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ In the previous example, we were returning a `dict` from our dependency ("depend
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
|
||||
|
|
@ -36,7 +36,7 @@ In the previous example, we were returning a `dict` from our dependency ("depend
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11"
|
||||
{!> ../../../docs_src/dependencies/tutorial001.py!}
|
||||
|
|
@ -124,7 +124,7 @@ Then, we can change the dependency "dependable" `common_parameters` from above t
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9-13"
|
||||
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
|
||||
|
|
@ -133,7 +133,7 @@ Then, we can change the dependency "dependable" `common_parameters` from above t
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11-15"
|
||||
{!> ../../../docs_src/dependencies/tutorial002.py!}
|
||||
|
|
@ -162,7 +162,7 @@ Pay attention to the `__init__` method used to create the instance of the class:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
|
||||
|
|
@ -171,7 +171,7 @@ Pay attention to the `__init__` method used to create the instance of the class:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="12"
|
||||
{!> ../../../docs_src/dependencies/tutorial002.py!}
|
||||
|
|
@ -200,7 +200,7 @@ Pay attention to the `__init__` method used to create the instance of the class:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
|
||||
|
|
@ -209,7 +209,7 @@ Pay attention to the `__init__` method used to create the instance of the class:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/dependencies/tutorial001.py!}
|
||||
|
|
@ -250,7 +250,7 @@ Now you can declare your dependency using this class.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/dependencies/tutorial002_py310.py!}
|
||||
|
|
@ -259,7 +259,7 @@ Now you can declare your dependency using this class.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19"
|
||||
{!> ../../../docs_src/dependencies/tutorial002.py!}
|
||||
|
|
@ -274,7 +274,7 @@ Notice how we write `CommonQueryParams` twice in the above code:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
||||
|
|
@ -309,7 +309,7 @@ In this case, the first `CommonQueryParams`, in:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons: CommonQueryParams ...
|
||||
|
|
@ -328,7 +328,7 @@ You could actually write just:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons = Depends(CommonQueryParams)
|
||||
|
|
@ -357,7 +357,7 @@ You could actually write just:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/dependencies/tutorial003_py310.py!}
|
||||
|
|
@ -366,7 +366,7 @@ You could actually write just:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19"
|
||||
{!> ../../../docs_src/dependencies/tutorial003.py!}
|
||||
|
|
@ -383,7 +383,7 @@ But you see that we are having some code repetition here, writing `CommonQueryPa
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
||||
|
|
@ -410,7 +410,7 @@ Instead of writing:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
||||
|
|
@ -427,7 +427,7 @@ Instead of writing:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
commons: CommonQueryParams = Depends()
|
||||
|
|
@ -458,7 +458,7 @@ The same example would then look like:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/dependencies/tutorial004_py310.py!}
|
||||
|
|
@ -467,7 +467,7 @@ The same example would then look like:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19"
|
||||
{!> ../../../docs_src/dependencies/tutorial004.py!}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ It should be a `list` of `Depends()`:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/dependencies/tutorial006.py!}
|
||||
|
|
@ -72,7 +72,7 @@ They can declare request requirements (like headers) or other sub-dependencies:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6 11"
|
||||
{!> ../../../docs_src/dependencies/tutorial006.py!}
|
||||
|
|
@ -97,7 +97,7 @@ These dependencies can `raise` exceptions, the same as normal dependencies:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8 13"
|
||||
{!> ../../../docs_src/dependencies/tutorial006.py!}
|
||||
|
|
@ -124,7 +124,7 @@ So, you can re-use a normal dependency (that returns a value) you already use so
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9 14"
|
||||
{!> ../../../docs_src/dependencies/tutorial006.py!}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ For example, `dependency_c` can have a dependency on `dependency_b`, and `depend
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4 12 20"
|
||||
{!> ../../../docs_src/dependencies/tutorial008.py!}
|
||||
|
|
@ -108,7 +108,7 @@ And, in turn, `dependency_b` needs the value from `dependency_a` (here named `de
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="16-17 24-25"
|
||||
{!> ../../../docs_src/dependencies/tutorial008.py!}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ In that case, they will be applied to all the *path operations* in the applicati
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="15"
|
||||
{!> ../../../docs_src/dependencies/tutorial012.py!}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ It is just a function that can take all the same parameters that a *path operati
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6-7"
|
||||
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
|
||||
|
|
@ -61,7 +61,7 @@ It is just a function that can take all the same parameters that a *path operati
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8-11"
|
||||
{!> ../../../docs_src/dependencies/tutorial001.py!}
|
||||
|
|
@ -108,7 +108,7 @@ And then it just returns a `dict` containing those values.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
|
||||
|
|
@ -117,7 +117,7 @@ And then it just returns a `dict` containing those values.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/dependencies/tutorial001.py!}
|
||||
|
|
@ -148,7 +148,7 @@ The same way you use `Body`, `Query`, etc. with your *path operation function* p
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11 16"
|
||||
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
|
||||
|
|
@ -157,7 +157,7 @@ The same way you use `Body`, `Query`, etc. with your *path operation function* p
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="15 20"
|
||||
{!> ../../../docs_src/dependencies/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ You could create a first dependency ("dependable") like:
|
|||
=== "Python 3.10 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6-7"
|
||||
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
|
||||
|
|
@ -40,7 +40,7 @@ You could create a first dependency ("dependable") like:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8-9"
|
||||
{!> ../../../docs_src/dependencies/tutorial005.py!}
|
||||
|
|
@ -75,7 +75,7 @@ Then you can create another dependency function (a "dependable") that at the sam
|
|||
=== "Python 3.10 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11"
|
||||
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
|
||||
|
|
@ -84,7 +84,7 @@ Then you can create another dependency function (a "dependable") that at the sam
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="13"
|
||||
{!> ../../../docs_src/dependencies/tutorial005.py!}
|
||||
|
|
@ -122,7 +122,7 @@ Then we can use the dependency with:
|
|||
=== "Python 3.10 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19"
|
||||
{!> ../../../docs_src/dependencies/tutorial005_py310.py!}
|
||||
|
|
@ -131,7 +131,7 @@ Then we can use the dependency with:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="22"
|
||||
{!> ../../../docs_src/dependencies/tutorial005.py!}
|
||||
|
|
@ -171,7 +171,7 @@ In an advanced scenario where you know you need the dependency to be called at e
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
async def needy_dependency(fresh_value: str = Depends(get_value, use_cache=False)):
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ Here's an example *path operation* with parameters using some of the above types
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 2 11-15"
|
||||
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
|
||||
|
|
@ -85,7 +85,7 @@ Here's an example *path operation* with parameters using some of the above types
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 2 12-16"
|
||||
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
|
||||
|
|
@ -114,7 +114,7 @@ Note that the parameters inside the function have their natural data type, and y
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17-18"
|
||||
{!> ../../../docs_src/extra_data_types/tutorial001_py310.py!}
|
||||
|
|
@ -123,7 +123,7 @@ Note that the parameters inside the function have their natural data type, and y
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="18-19"
|
||||
{!> ../../../docs_src/extra_data_types/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ First import `Header`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
|
||||
|
|
@ -36,7 +36,7 @@ First import `Header`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/header_params/tutorial001.py!}
|
||||
|
|
@ -69,7 +69,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/header_params/tutorial001_py310.py!}
|
||||
|
|
@ -78,7 +78,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/header_params/tutorial001.py!}
|
||||
|
|
@ -129,7 +129,7 @@ If for some reason you need to disable automatic conversion of underscores to hy
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/header_params/tutorial002_py310.py!}
|
||||
|
|
@ -138,7 +138,7 @@ If for some reason you need to disable automatic conversion of underscores to hy
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/header_params/tutorial002.py!}
|
||||
|
|
@ -178,7 +178,7 @@ For example, to declare a header of `X-Token` that can appear more than once, yo
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/header_params/tutorial003_py310.py!}
|
||||
|
|
@ -187,7 +187,7 @@ For example, to declare a header of `X-Token` that can appear more than once, yo
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/header_params/tutorial003_py39.py!}
|
||||
|
|
@ -196,7 +196,7 @@ For example, to declare a header of `X-Token` that can appear more than once, yo
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/header_params/tutorial003.py!}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ First, import `Path` from `fastapi`, and import `Annotated`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
|
||||
|
|
@ -36,7 +36,7 @@ First, import `Path` from `fastapi`, and import `Annotated`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
|
||||
|
|
@ -69,7 +69,7 @@ For example, to declare a `title` metadata value for the path parameter `item_id
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial001_py310.py!}
|
||||
|
|
@ -78,7 +78,7 @@ For example, to declare a `title` metadata value for the path parameter `item_id
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial001.py!}
|
||||
|
|
@ -113,7 +113,7 @@ So, you can declare your function as:
|
|||
=== "Python 3.6 non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial002.py!}
|
||||
|
|
@ -194,7 +194,7 @@ Here, with `ge=1`, `item_id` will need to be an integer number "`g`reater than o
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial004.py!}
|
||||
|
|
@ -222,7 +222,7 @@ The same applies for:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial005.py!}
|
||||
|
|
@ -253,7 +253,7 @@ And the same for <abbr title="less than"><code>lt</code></abbr>.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11"
|
||||
{!> ../../../docs_src/path_params_numeric_validations/tutorial006.py!}
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ You can also add a parameter `min_length`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial003_py310.py!}
|
||||
|
|
@ -262,7 +262,7 @@ You can also add a parameter `min_length`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial003.py!}
|
||||
|
|
@ -293,7 +293,7 @@ You can define a <abbr title="A regular expression, regex or regexp is a sequenc
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial004_py310.py!}
|
||||
|
|
@ -302,7 +302,7 @@ You can define a <abbr title="A regular expression, regex or regexp is a sequenc
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial004.py!}
|
||||
|
|
@ -339,7 +339,7 @@ Let's say that you want to declare the `q` query parameter to have a `min_length
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial005.py!}
|
||||
|
|
@ -393,7 +393,7 @@ So, when you need to declare a value as required while using `Query`, you can si
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial006.py!}
|
||||
|
|
@ -423,7 +423,7 @@ There's an alternative way to explicitly declare that a value is required. You c
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial006b.py!}
|
||||
|
|
@ -463,7 +463,7 @@ To do that, you can declare that `None` is a valid type but still use `...` as t
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial006c_py310.py!}
|
||||
|
|
@ -472,7 +472,7 @@ To do that, you can declare that `None` is a valid type but still use `...` as t
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial006c.py!}
|
||||
|
|
@ -500,7 +500,7 @@ If you feel uncomfortable using `...`, you can also import and use `Required` fr
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 8"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial006d.py!}
|
||||
|
|
@ -536,7 +536,7 @@ For example, to declare a query parameter `q` that can appear multiple times in
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial011_py310.py!}
|
||||
|
|
@ -545,7 +545,7 @@ For example, to declare a query parameter `q` that can appear multiple times in
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial011_py39.py!}
|
||||
|
|
@ -554,7 +554,7 @@ For example, to declare a query parameter `q` that can appear multiple times in
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial011.py!}
|
||||
|
|
@ -605,7 +605,7 @@ And you can also define a default `list` of values if none are provided:
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial012_py39.py!}
|
||||
|
|
@ -614,7 +614,7 @@ And you can also define a default `list` of values if none are provided:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial012.py!}
|
||||
|
|
@ -656,7 +656,7 @@ You can also use `list` directly instead of `List[str]` (or `list[str]` in Pytho
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial013.py!}
|
||||
|
|
@ -701,7 +701,7 @@ You can add a `title`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial007_py310.py!}
|
||||
|
|
@ -710,7 +710,7 @@ You can add a `title`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial007.py!}
|
||||
|
|
@ -739,7 +739,7 @@ And a `description`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="12"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial008_py310.py!}
|
||||
|
|
@ -748,7 +748,7 @@ And a `description`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="13"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial008.py!}
|
||||
|
|
@ -793,7 +793,7 @@ Then you can declare an `alias`, and that alias is what will be used to find the
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial009_py310.py!}
|
||||
|
|
@ -802,7 +802,7 @@ Then you can declare an `alias`, and that alias is what will be used to find the
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial009.py!}
|
||||
|
|
@ -837,7 +837,7 @@ Then pass the parameter `deprecated=True` to `Query`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial010_py310.py!}
|
||||
|
|
@ -846,7 +846,7 @@ Then pass the parameter `deprecated=True` to `Query`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="18"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial010.py!}
|
||||
|
|
@ -881,7 +881,7 @@ To exclude a query parameter from the generated OpenAPI schema (and thus, from t
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial014_py310.py!}
|
||||
|
|
@ -890,7 +890,7 @@ To exclude a query parameter from the generated OpenAPI schema (and thus, from t
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/query_params_str_validations/tutorial014.py!}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ Import `File` and `UploadFile` from `fastapi`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
|
|
@ -53,7 +53,7 @@ Create file parameters the same way you would for `Body` or `Form`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
|
|
@ -94,7 +94,7 @@ Define a file parameter with a type of `UploadFile`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="12"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
|
|
@ -190,7 +190,7 @@ You can make a file optional by using standard type annotations and setting a de
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7 15"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02_py310.py!}
|
||||
|
|
@ -199,7 +199,7 @@ You can make a file optional by using standard type annotations and setting a de
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9 17"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02.py!}
|
||||
|
|
@ -224,7 +224,7 @@ You can also use `File()` with `UploadFile`, for example, to set additional meta
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7 13"
|
||||
{!> ../../../docs_src/request_files/tutorial001_03.py!}
|
||||
|
|
@ -253,7 +253,7 @@ To use that, declare a list of `bytes` or `UploadFile`:
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8 13"
|
||||
{!> ../../../docs_src/request_files/tutorial002_py39.py!}
|
||||
|
|
@ -262,7 +262,7 @@ To use that, declare a list of `bytes` or `UploadFile`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10 15"
|
||||
{!> ../../../docs_src/request_files/tutorial002.py!}
|
||||
|
|
@ -294,7 +294,7 @@ And the same way as before, you can use `File()` to set additional parameters, e
|
|||
=== "Python 3.9+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9 16"
|
||||
{!> ../../../docs_src/request_files/tutorial003_py39.py!}
|
||||
|
|
@ -303,7 +303,7 @@ And the same way as before, you can use `File()` to set additional parameters, e
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="11 18"
|
||||
{!> ../../../docs_src/request_files/tutorial003.py!}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ You can define files and form fields at the same time using `File` and `Form`.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/request_forms_and_files/tutorial001.py!}
|
||||
|
|
@ -49,7 +49,7 @@ Create file and form parameters the same way you would for `Body` or `Query`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/request_forms_and_files/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Import `Form` from `fastapi`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/request_forms/tutorial001.py!}
|
||||
|
|
@ -51,7 +51,7 @@ Create form parameters the same way you would for `Body` or `Query`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/request_forms/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ Here we pass an `example` of the data expected in `Body()`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="20-25"
|
||||
{!> ../../../docs_src/schema_extra_example/tutorial003.py!}
|
||||
|
|
@ -145,7 +145,7 @@ Each specific example `dict` in the `examples` can contain:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="21-47"
|
||||
{!> ../../../docs_src/schema_extra_example/tutorial004.py!}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Copy the example in a file `main.py`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/security/tutorial001.py!}
|
||||
|
|
@ -149,7 +149,7 @@ When we create an instance of the `OAuth2PasswordBearer` class we pass in the `t
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!> ../../../docs_src/security/tutorial001.py!}
|
||||
|
|
@ -200,7 +200,7 @@ Now you can pass that `oauth2_scheme` in a dependency with `Depends`.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/security/tutorial001.py!}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ In the previous chapter the security system (which is based on the dependency in
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/security/tutorial001.py!}
|
||||
|
|
@ -54,7 +54,7 @@ The same way we use Pydantic to declare bodies, we can use it anywhere else:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3 10-14"
|
||||
{!> ../../../docs_src/security/tutorial002_py310.py!}
|
||||
|
|
@ -63,7 +63,7 @@ The same way we use Pydantic to declare bodies, we can use it anywhere else:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="5 12-16"
|
||||
{!> ../../../docs_src/security/tutorial002.py!}
|
||||
|
|
@ -100,7 +100,7 @@ The same as we were doing before in the *path operation* directly, our new depen
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="23"
|
||||
{!> ../../../docs_src/security/tutorial002_py310.py!}
|
||||
|
|
@ -109,7 +109,7 @@ The same as we were doing before in the *path operation* directly, our new depen
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="25"
|
||||
{!> ../../../docs_src/security/tutorial002.py!}
|
||||
|
|
@ -140,7 +140,7 @@ The same as we were doing before in the *path operation* directly, our new depen
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="17-20 24-25"
|
||||
{!> ../../../docs_src/security/tutorial002_py310.py!}
|
||||
|
|
@ -149,7 +149,7 @@ The same as we were doing before in the *path operation* directly, our new depen
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="19-22 26-27"
|
||||
{!> ../../../docs_src/security/tutorial002.py!}
|
||||
|
|
@ -180,7 +180,7 @@ So now we can use the same `Depends` with our `get_current_user` in the *path op
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="29"
|
||||
{!> ../../../docs_src/security/tutorial002_py310.py!}
|
||||
|
|
@ -189,7 +189,7 @@ So now we can use the same `Depends` with our `get_current_user` in the *path op
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="31"
|
||||
{!> ../../../docs_src/security/tutorial002.py!}
|
||||
|
|
@ -262,7 +262,7 @@ And all these thousands of *path operations* can be as small as 3 lines:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="28-30"
|
||||
{!> ../../../docs_src/security/tutorial002_py310.py!}
|
||||
|
|
@ -271,7 +271,7 @@ And all these thousands of *path operations* can be as small as 3 lines:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="30-32"
|
||||
{!> ../../../docs_src/security/tutorial002.py!}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ And another one to authenticate and return a user.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6 47 54-55 58-59 68-74"
|
||||
{!> ../../../docs_src/security/tutorial004_py310.py!}
|
||||
|
|
@ -139,7 +139,7 @@ And another one to authenticate and return a user.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7 48 55-56 59-60 69-75"
|
||||
{!> ../../../docs_src/security/tutorial004.py!}
|
||||
|
|
@ -197,7 +197,7 @@ Create a utility function to generate a new access token.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="5 11-13 27-29 77-85"
|
||||
{!> ../../../docs_src/security/tutorial004_py310.py!}
|
||||
|
|
@ -206,7 +206,7 @@ Create a utility function to generate a new access token.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="6 12-14 28-30 78-86"
|
||||
{!> ../../../docs_src/security/tutorial004.py!}
|
||||
|
|
@ -241,7 +241,7 @@ If the token is invalid, return an HTTP error right away.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="88-105"
|
||||
{!> ../../../docs_src/security/tutorial004_py310.py!}
|
||||
|
|
@ -250,7 +250,7 @@ If the token is invalid, return an HTTP error right away.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="89-106"
|
||||
{!> ../../../docs_src/security/tutorial004.py!}
|
||||
|
|
@ -283,7 +283,7 @@ Create a real JWT access token and return it
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="114-127"
|
||||
{!> ../../../docs_src/security/tutorial004_py310.py!}
|
||||
|
|
@ -292,7 +292,7 @@ Create a real JWT access token and return it
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="115-128"
|
||||
{!> ../../../docs_src/security/tutorial004.py!}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ First, import `OAuth2PasswordRequestForm`, and use it as a dependency with `Depe
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="2 74"
|
||||
{!> ../../../docs_src/security/tutorial003_py310.py!}
|
||||
|
|
@ -79,7 +79,7 @@ First, import `OAuth2PasswordRequestForm`, and use it as a dependency with `Depe
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="4 76"
|
||||
{!> ../../../docs_src/security/tutorial003.py!}
|
||||
|
|
@ -143,7 +143,7 @@ For the error, we use the exception `HTTPException`:
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1 75-77"
|
||||
{!> ../../../docs_src/security/tutorial003_py310.py!}
|
||||
|
|
@ -152,7 +152,7 @@ For the error, we use the exception `HTTPException`:
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3 77-79"
|
||||
{!> ../../../docs_src/security/tutorial003.py!}
|
||||
|
|
@ -203,7 +203,7 @@ So, the thief won't be able to try to use those same passwords in another system
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="78-81"
|
||||
{!> ../../../docs_src/security/tutorial003_py310.py!}
|
||||
|
|
@ -212,7 +212,7 @@ So, the thief won't be able to try to use those same passwords in another system
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="80-83"
|
||||
{!> ../../../docs_src/security/tutorial003.py!}
|
||||
|
|
@ -273,7 +273,7 @@ For this simple example, we are going to just be completely insecure and return
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="83"
|
||||
{!> ../../../docs_src/security/tutorial003_py310.py!}
|
||||
|
|
@ -282,7 +282,7 @@ For this simple example, we are going to just be completely insecure and return
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="85"
|
||||
{!> ../../../docs_src/security/tutorial003.py!}
|
||||
|
|
@ -330,7 +330,7 @@ So, in our endpoint, we will only get a user if the user exists, was correctly a
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="56-64 67-70 88"
|
||||
{!> ../../../docs_src/security/tutorial003_py310.py!}
|
||||
|
|
@ -339,7 +339,7 @@ So, in our endpoint, we will only get a user if the user exists, was correctly a
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="58-66 69-72 90"
|
||||
{!> ../../../docs_src/security/tutorial003.py!}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ Both *path operations* require an `X-Token` header.
|
|||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/app_testing/app_b_py310/main.py!}
|
||||
|
|
@ -140,7 +140,7 @@ Both *path operations* require an `X-Token` header.
|
|||
=== "Python 3.6+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Try to use the main, `Annotated` version better.
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/app_testing/app_b/main.py!}
|
||||
|
|
|
|||
Loading…
Reference in New Issue