mirror of https://github.com/tiangolo/fastapi.git
📝 fix typos in nested models and OAuth2 with JWT (#127)
This commit is contained in:
parent
e68a68c97c
commit
c1da3b38a3
|
|
@ -1,8 +1,7 @@
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, UrlStr
|
||||||
from pydantic.types import UrlStr
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, UrlStr
|
||||||
from pydantic.types import UrlStr
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
@ -18,7 +17,7 @@ class Item(BaseModel):
|
||||||
price: float
|
price: float
|
||||||
tax: float = None
|
tax: float = None
|
||||||
tags: Set[str] = []
|
tags: Set[str] = []
|
||||||
image: List[Image] = None
|
images: List[Image] = None
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
@app.put("/items/{item_id}")
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, UrlStr
|
||||||
from pydantic.types import UrlStr
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
@ -18,7 +17,7 @@ class Item(BaseModel):
|
||||||
price: float
|
price: float
|
||||||
tax: float = None
|
tax: float = None
|
||||||
tags: Set[str] = []
|
tags: Set[str] = []
|
||||||
image: List[Image] = None
|
images: List[Image] = None
|
||||||
|
|
||||||
|
|
||||||
class Offer(BaseModel):
|
class Offer(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, UrlStr
|
||||||
from pydantic.types import UrlStr
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ To see all the options you have, checkout the docs for <a href="https://pydantic
|
||||||
|
|
||||||
For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `UrlStr`:
|
For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `UrlStr`:
|
||||||
|
|
||||||
```Python hl_lines="5 11"
|
```Python hl_lines="4 10"
|
||||||
{!./src/body_nested_models/tutorial005.py!}
|
{!./src/body_nested_models/tutorial005.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ The string will be checked to be a valid URL, and documented in JSON Schema / Op
|
||||||
|
|
||||||
You can also use Pydantic models as subtypes of `list`, `set`, etc:
|
You can also use Pydantic models as subtypes of `list`, `set`, etc:
|
||||||
|
|
||||||
```Python hl_lines="21"
|
```Python hl_lines="20"
|
||||||
{!./src/body_nested_models/tutorial006.py!}
|
{!./src/body_nested_models/tutorial006.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ This will expect (convert, validate, document, etc) a JSON body like:
|
||||||
|
|
||||||
You can define arbitrarily deeply nested models:
|
You can define arbitrarily deeply nested models:
|
||||||
|
|
||||||
```Python hl_lines="10 15 21 24 28"
|
```Python hl_lines="9 14 20 23 27"
|
||||||
{!./src/body_nested_models/tutorial007.py!}
|
{!./src/body_nested_models/tutorial007.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ images: List[Image]
|
||||||
|
|
||||||
as in:
|
as in:
|
||||||
|
|
||||||
```Python hl_lines="16"
|
```Python hl_lines="15"
|
||||||
{!./src/body_nested_models/tutorial008.py!}
|
{!./src/body_nested_models/tutorial008.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ If you want to play with JWT tokens and see how they work, check <a href="https:
|
||||||
|
|
||||||
## Install `PyJWT`
|
## Install `PyJWT`
|
||||||
|
|
||||||
We need to install `PyJWT` to generate and verity the JWT tokens in Python:
|
We need to install `PyJWT` to generate and verify the JWT tokens in Python:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install pyjwt
|
pip install pyjwt
|
||||||
|
|
@ -198,7 +198,7 @@ Many packages that simplify it a lot have to make many compromises with the data
|
||||||
|
|
||||||
**FastAPI** doesn't make any compromise with any database, data model or tool.
|
**FastAPI** doesn't make any compromise with any database, data model or tool.
|
||||||
|
|
||||||
It gives you all the flexibility to chose the ones that fit your project the best.
|
It gives you all the flexibility to choose the ones that fit your project the best.
|
||||||
|
|
||||||
And you can use directly many well maintained and widely used packages like `passlib` and `pyjwt`, because **FastAPI** doesn't require any complex mechanisms to integrate external packages.
|
And you can use directly many well maintained and widely used packages like `passlib` and `pyjwt`, because **FastAPI** doesn't require any complex mechanisms to integrate external packages.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue