Unsure about these

This commit is contained in:
Nils Lindemann 2024-04-01 20:19:09 +02:00
parent bdc929a92a
commit c5e41001ce
6 changed files with 10 additions and 10 deletions

View File

@ -543,7 +543,7 @@ Here's how the hierarchy of dependencies and scopes looks like:
* This `security_scopes` parameter has a property `scopes` with a `list` containing all these scopes declared above, so:
* `security_scopes.scopes` will contain `["me", "items"]` for the *path operation* `read_own_items`.
* `security_scopes.scopes` will contain `["me"]` for the *path operation* `read_users_me`, because it is declared in the dependency `get_current_active_user`.
* `security_scopes.scopes` will contain `[]` (nothing) for the *path operation* `read_system_status`, because it didn't declare any `Security` with `scopes`, and its dependency, `get_current_user`, doesn't declare any `scope` either.
* `security_scopes.scopes` will contain `[]` (nothing) for the *path operation* `read_system_status`, because it didn't declare any `Security` with `scopes`, and its dependency, `get_current_user`, doesn't declare any `scopes` either.
!!! tip
The important and "magic" thing here is that `get_current_user` will have a different list of `scopes` to check for each *path operation*.

View File

@ -46,7 +46,7 @@ First import `Cookie`:
Then declare the cookie parameters using the same structure as with `Path` and `Query`.
The first value is the default value, you can pass all the extra validation or annotation parameters:
The first value is the type. You can pass to `Cookie` all the extra validation or annotation parameters. After that you may declare a default value:
=== "Python 3.10+"

View File

@ -46,7 +46,7 @@ First import `Header`:
Then declare the header parameters using the same structure as with `Path`, `Query` and `Cookie`.
The first value is the default value, you can pass all the extra validation or annotation parameters:
The first value is the type. You can pass to `Header` all the extra validation or annotation parameters. After that you may declare a default value:
=== "Python 3.10+"

View File

@ -369,7 +369,7 @@ Let's say that you want to declare the `q` query parameter to have a `min_length
!!! note
Having a default value of any type, including `None`, makes the parameter optional (not required).
## Make it required
## Required params
When we don't need to declare more validations or metadata, we can make the `q` query parameter required just by not declaring a default value, like:
@ -457,7 +457,7 @@ There's an alternative way to explicitly declare that a value is required. You c
This will let **FastAPI** know that this parameter is required.
### Required with `None`
### Required, can be `None`
You can declare that a parameter can accept `None`, but that it's still required. This would force clients to send a value, even if the value is `None`.
@ -633,7 +633,7 @@ the default of `q` will be: `["foo", "bar"]` and your response will be:
}
```
#### Using `list`
#### Using just `list`
You can also use `list` directly instead of `List[str]` (or `list[str]` in Python 3.9+):
@ -852,7 +852,7 @@ The docs will show it like this:
<img src="/img/tutorial/query-params-str-validations/image01.png">
## Exclude from OpenAPI
## Exclude parameter from OpenAPI
To exclude a query parameter from the generated OpenAPI schema (and thus, from the automatic documentation systems), set the parameter `include_in_schema` of `Query` to `False`:

View File

@ -192,7 +192,7 @@ That's why in this example we have to declare it in the `response_model` paramet
## Return Type and Data Filtering
Let's continue from the previous example. We wanted to **annotate the function with one type** but return something that includes **more data**.
Let's continue from the previous example. We wanted to **annotate the function with one type** but return something that includes **less data**.
We want FastAPI to keep **filtering** the data using the response model.
@ -258,7 +258,7 @@ The most common case would be [returning a Response directly as explained later
{!> ../../../docs_src/response_model/tutorial003_02.py!}
```
This simple case is handled automatically by FastAPI because the return type annotation is the class (or a subclass) of `Response`.
This simple case is handled automatically by FastAPI because the return type annotation is the class (or a subclass of) `Response`.
And tools will also be happy because both `RedirectResponse` and `JSONResponse` are subclasses of `Response`, so the type annotation is correct.

View File

@ -47,7 +47,7 @@ Here we are using the recommended one: <a href="https://cryptography.io/" class=
!!! tip
This tutorial previously used <a href="https://pyjwt.readthedocs.io/" class="external-link" target="_blank">PyJWT</a>.
But it was updated to use Python-jose instead as it provides all the features from PyJWT plus some extras that you might need later when building integrations with other tools.
But it was updated to use python-jose instead as it provides all the features from PyJWT plus some extras that you might need later when building integrations with other tools.
## Password hashing