mirror of https://github.com/tiangolo/fastapi.git
✏️ Fix typos and docs notes
This commit is contained in:
parent
5278314f2f
commit
660f917d79
|
|
@ -33,7 +33,7 @@ But you can also declare multiple body parameters, e.g. `item` and `user`:
|
|||
{!./src/body_multiple_params/tutorial002.py!}
|
||||
```
|
||||
|
||||
In this case, **FastAPI** will notice that there are more than one body parameter in the function (two parameters that are Pydantic models).
|
||||
In this case, **FastAPI** will notice that there are more than one body parameters in the function (two parameters that are Pydantic models).
|
||||
|
||||
So, it will then use the parameter names as keys (field names) in the body, and expect a body like:
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ First, you have to import it:
|
|||
```
|
||||
|
||||
!!! warning
|
||||
Notice that `Schema` is imported directly from `pydantic`, not form `fastapi` as are all the rest (`Query`, `Path`, `Body`, etc).
|
||||
Notice that `Schema` is imported directly from `pydantic`, not from `fastapi` as are all the rest (`Query`, `Path`, `Body`, etc).
|
||||
|
||||
|
||||
## Declare model attributes
|
||||
|
|
@ -37,7 +37,7 @@ In `Schema`, `Path`, `Query`, `Body` and others you'll see later, you can declar
|
|||
|
||||
Those parameters will be added as-is to the output JSON Schema.
|
||||
|
||||
If you know JSON Schema and want to add extra information appart from what we have discussed here, you can pass that as extra keyword arguments.
|
||||
If you know JSON Schema and want to add extra information apart from what we have discussed here, you can pass that as extra keyword arguments.
|
||||
|
||||
!!! warning
|
||||
Have in mind that extra parameters passed won't add any validation, only annotation, for documentation purposes.
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ And will be also used in the API docs inside each path operation that needs them
|
|||
|
||||
## Editor support
|
||||
|
||||
In your editor, inside your function you will get type hints and completion everywhere (this wouldn't happen if your received a `dict` instead of a Pydantic model):
|
||||
In your editor, inside your function you will get type hints and completion everywhere (this wouldn't happen if you received a `dict` instead of a Pydantic model):
|
||||
|
||||
<img src="/img/tutorial/body/image03.png">
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
You can define Cookie parameters the same way you define `Query` and `Path` parameteres.
|
||||
You can define Cookie parameters the same way you define `Query` and `Path` parameters.
|
||||
|
||||
## Import `Cookie`
|
||||
|
||||
|
|
@ -8,11 +8,11 @@ First import `Cookie`:
|
|||
{!./src/cookie_params/tutorial001.py!}
|
||||
```
|
||||
|
||||
## Declare `Cookie` parameteres
|
||||
## Declare `Cookie` parameters
|
||||
|
||||
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 parameteres:
|
||||
The first value is the default value, you can pass all the extra validation or annotation parameters:
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!./src/cookie_params/tutorial001.py!}
|
||||
|
|
@ -22,7 +22,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
`Cookie` is a "sister" class of `Path` and `Query`. It also inherits from the same common `Param` class.
|
||||
|
||||
!!! info
|
||||
To declare cookies, you need to use `Cookie`, because otherwise the parameters would be interpreted as query parameteres.
|
||||
To declare cookies, you need to use `Cookie`, because otherwise the parameters would be interpreted as query parameters.
|
||||
|
||||
## Recap
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Pass `HTMLResponse` as the parameter `content_type` of your path operation:
|
|||
And it will be documented as such in OpenAPI.
|
||||
|
||||
|
||||
### return a Starlette `Response`
|
||||
### Return a Starlette `Response`
|
||||
|
||||
You can also override the response directly in your path operation.
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ What FastAPI actually checks is that it is a "callable" (function, class or anyt
|
|||
|
||||
If you pass a "callable" as a dependency in **FastAPI**, it will analyze the parameters for that "callable", and process them in the same way as the parameters for a path operation function. Including sub-dependencies.
|
||||
|
||||
That also applies to callables with no parameters at all. The same as would be for path operation functions with no parameteres.
|
||||
That also applies to callables with no parameters at all. The same as would be for path operation functions with no parameters.
|
||||
|
||||
Then, we can change the dependency "dependable" `common_parameters` from above to the class `CommonQueryParameters`:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
You can define Header parameters the same way you define `Query`, `Path` and `Cookie` parameteres.
|
||||
You can define Header parameters the same way you define `Query`, `Path` and `Cookie` parameters.
|
||||
|
||||
## Import `Header`
|
||||
|
||||
|
|
@ -8,11 +8,11 @@ First import `Header`:
|
|||
{!./src/header_params/tutorial001.py!}
|
||||
```
|
||||
|
||||
## Declare `Header` parameteres
|
||||
## Declare `Header` parameters
|
||||
|
||||
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 parameteres:
|
||||
The first value is the default value, you can pass all the extra validation or annotation parameters:
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!./src/header_params/tutorial001.py!}
|
||||
|
|
@ -22,7 +22,7 @@ The first value is the default value, you can pass all the extra validation or a
|
|||
`Header` is a "sister" class of `Path`, `Query` and `Cookie`. It also inherits from the same common `Param` class.
|
||||
|
||||
!!! info
|
||||
To declare headers, you need to use `Header`, because otherwise the parameters would be interpreted as query parameteres.
|
||||
To declare headers, you need to use `Header`, because otherwise the parameters would be interpreted as query parameters.
|
||||
|
||||
## Automatic conversion
|
||||
|
||||
|
|
@ -49,6 +49,6 @@ If for some reason you need to disable automatic conversion of underscores to hy
|
|||
|
||||
## Recap
|
||||
|
||||
Declare headeres with `Header`, using the same common pattern as `Query`, `Path` and `Cookie`.
|
||||
Declare headers with `Header`, using the same common pattern as `Query`, `Path` and `Cookie`.
|
||||
|
||||
And don't worry about underscores in your variables, **FastAPI** will take care of converting them.
|
||||
|
|
|
|||
|
|
@ -130,6 +130,11 @@ You can add more information about the parameter.
|
|||
|
||||
That information will be included in the generated OpenAPI and used by the documentation user interfaces and external tools.
|
||||
|
||||
!!! note
|
||||
Have in mind that different tools might have different levels of OpenAPI support.
|
||||
|
||||
Some of them might not show all the extra information declared yet, although in most of the cases, the missing feature is already planned for development.
|
||||
|
||||
You can add a `title`:
|
||||
|
||||
```Python hl_lines="7"
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ When you declare a default value for non-path parameters (for now, we have only
|
|||
|
||||
If you don't want to add a specific value but just make it optional, set the default as `None`.
|
||||
|
||||
But when you want to make a query parameter required, you can just do not declare any default value:
|
||||
But when you want to make a query parameter required, you can just not declare any default value:
|
||||
|
||||
```Python hl_lines="6 7"
|
||||
{!./src/query_params/tutorial005.py!}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ The files will be uploaded as form data and you will receive the contents as `by
|
|||
`File` is a class that inherits directly from `Form`.
|
||||
|
||||
!!! info
|
||||
To declare File bodies, you need to use `File`, because otherwise the parameters would be interpreted as query parameteres or body (JSON) parameters.
|
||||
To declare File bodies, you need to use `File`, because otherwise the parameters would be interpreted as query parameters or body (JSON) parameters.
|
||||
|
||||
## "Form Data"?
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ With `Form` you can declare the same metadata and validation as with `Body` (and
|
|||
`Form` is a class that inherits directly from `Body`.
|
||||
|
||||
!!! info
|
||||
To declare form bodies, you need to use `Form` explicitly, because without it the parameters would be interpreted as query parameteres or body (JSON) parameters.
|
||||
To declare form bodies, you need to use `Form` explicitly, because without it the parameters would be interpreted as query parameters or body (JSON) parameters.
|
||||
|
||||
## "Form Fields"?
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ Now, whenever a browser is creating a user with a password, the API will return
|
|||
|
||||
In this case, it might not be a problem, becase the user himself is sending the password.
|
||||
|
||||
But if we use sthe same model for another path operation, we could be sending the passwords of our users to every client.
|
||||
But if we use the same model for another path operation, we could be sending the passwords of our users to every client.
|
||||
|
||||
!!! danger
|
||||
Never send the plain password of a user in a response.
|
||||
|
|
|
|||
Loading…
Reference in New Issue