# ๐ช - ๐ ๐ท
โฎ๏ธ **FastAPI**, ๐ ๐ช ๐ฌ, โ, ๐, & โ๏ธ ๐ฒ ๐ ๐ฆ ๐ท (๐ Pydantic).
## ๐ ๐
๐ ๐ช ๐ฌ ๐ข ๐พ. ๐ผ, ๐ `list`:
{* ../../docs_src/body_nested_models/tutorial001.py hl[14] *}
๐ ๐ โ `tags` ๐, ๐ โซ๏ธ ๐ซ ๐ฃ ๐ ๐ฃ ๐.
## ๐ ๐ โฎ๏ธ ๐ ๐ข
โ๏ธ ๐ โ๏ธ ๐ฏ ๐ ๐ฃ ๐ โฎ๏ธ ๐ ๐, โ๏ธ "๐ ๐ข":
### ๐ โจ `List`
๐ 3๏ธโฃ.9๏ธโฃ & ๐ ๐ ๐ช โ๏ธ ๐ฉ `list` ๐ฃ ๐ซ ๐ โ ๐ฅ ๐ ๐ ๐. ๐ถ
โ๏ธ ๐ โฌ โญ 3๏ธโฃ.9๏ธโฃ (3๏ธโฃ.6๏ธโฃ & ๐), ๐ ๐ฅ ๐ช ๐ `List` โช๏ธโก๏ธ ๐ฉ ๐ `typing` ๐น:
{* ../../docs_src/body_nested_models/tutorial002.py hl[1] *}
### ๐ฃ `list` โฎ๏ธ ๐ ๐ข
๐ฃ ๐ ๐ โ๏ธ ๐ ๐ข (๐ ๐), ๐ `list`, `dict`, `tuple`:
* ๐ฅ ๐ ๐ โฌ ๐
๐ 3๏ธโฃ.9๏ธโฃ, ๐ ๐ซ ๐ โฌ โช๏ธโก๏ธ `typing` ๐น
* ๐ถโโ๏ธ ๐ ๐(โ) "๐ ๐ข" โ๏ธ โฌ ๐: `[` & `]`
๐ 3๏ธโฃ.9๏ธโฃ โซ๏ธ ๐:
```Python
my_list: list[str]
```
โฌ ๐ โญ 3๏ธโฃ.9๏ธโฃ, โซ๏ธ ๐:
```Python
from typing import List
my_list: List[str]
```
๐ ๐ ๐ฉ ๐ โ ๐ ๐.
โ๏ธ ๐ ๐ ๐ฉ โ ๐ท ๐ข โฎ๏ธ ๐ ๐.
, ๐ ๐ผ, ๐ฅ ๐ช โ `tags` ๐ฏ "๐ ๐ป":
{* ../../docs_src/body_nested_models/tutorial002.py hl[14] *}
## โ ๐
โ๏ธ โคด๏ธ ๐ฅ ๐ญ ๐ โซ๏ธ, & ๐ค ๐ ๐ ๐ซ๐ ๐ซ ๐, ๐ซ ๐ ๐ฒ ๐ ๐ป.
& ๐ โ๏ธ ๐ ๐ฝ ๐ โ ๐ ๐ฌ, `set`.
โคด๏ธ ๐ฅ ๐ช ๐ฃ `tags` โ ๐ป:
{* ../../docs_src/body_nested_models/tutorial003.py hl[1,14] *}
โฎ๏ธ ๐, ๐ฅ ๐ ๐จ ๐จ โฎ๏ธ โ ๐, โซ๏ธ ๐ ๐ โ ๐ ๐ฌ.
& ๐โ ๐ ๐ข ๐ ๐, ๐ฅ โน โ๏ธ โ, โซ๏ธ ๐ ๐ข โ ๐ ๐ฌ.
& โซ๏ธ ๐ โ / ๐ โก๏ธ ๐โโ๏ธ.
## ๐ฆ ๐ท
๐ ๐ข Pydantic ๐ท โ๏ธ ๐.
โ๏ธ ๐ ๐ ๐ช โซ๏ธ โ1๏ธโฃ Pydantic ๐ท.
, ๐ ๐ช ๐ฃ ๐ ๐ฆ ๐ป "๐" โฎ๏ธ ๐ฏ ๐ข ๐, ๐ & ๐ฌ.
๐ ๐, ๐ฒ ๐ฆ.
### ๐ฌ ๐
๐ผ, ๐ฅ ๐ช ๐ฌ `Image` ๐ท:
{* ../../docs_src/body_nested_models/tutorial004.py hl[9:11] *}
### โ๏ธ ๐ ๐
& โคด๏ธ ๐ฅ ๐ช โ๏ธ โซ๏ธ ๐ ๐ข:
{* ../../docs_src/body_nested_models/tutorial004.py hl[20] *}
๐ ๐ โ ๐ **FastAPI** ๐ โ ๐ช ๐:
```JSON
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": ["rock", "metal", "bar"],
"image": {
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
}
}
```
๐, ๐คธ ๐ ๐, โฎ๏ธ **FastAPI** ๐ ๐ค:
* ๐จโ๐จ ๐โ๐ฆบ (๐ ๏ธ, โ๏ธ), ๐ฆ ๐ท
* ๐ฝ ๐ ๏ธ
* ๐ฝ ๐ฌ
* ๐ง ๐งพ
## ๐ ๐ & ๐ฌ
โ๏ธ โช๏ธโก๏ธ ๐ โญ ๐ ๐ `str`, `int`, `float`, โ๏ธ. ๐ ๐ช โ๏ธ ๐
๐ โญ ๐ ๐ ๐ โช๏ธโก๏ธ `str`.
๐ ๐ ๐ ๐ โ๏ธ, ๐ ๐ฉบ Pydantic ๐ ๐. ๐ ๐ ๐ ๐ผ โญ ๐.
๐ผ, `Image` ๐ท ๐ฅ โ๏ธ `url` ๐, ๐ฅ ๐ช ๐ฃ โซ๏ธ โฉ๏ธ `str`, Pydantic `HttpUrl`:
{* ../../docs_src/body_nested_models/tutorial005.py hl[4,10] *}
๐ป ๐ โ
โ ๐, & ๐ ๐ป ๐ / ๐ โ
.
## ๐ข โฎ๏ธ ๐ ๐
๐ ๐ช โ๏ธ Pydantic ๐ท ๐พ `list`, `set`, โ๏ธ:
{* ../../docs_src/body_nested_models/tutorial006.py hl[20] *}
๐ ๐ โ (๐, โ, ๐, โ๏ธ) ๐ป ๐ช ๐:
```JSON hl_lines="11"
{
"name": "Foo",
"description": "The pretender",
"price": 42.0,
"tax": 3.2,
"tags": [
"rock",
"metal",
"bar"
],
"images": [
{
"url": "http://example.com/baz.jpg",
"name": "The Foo live"
},
{
"url": "http://example.com/dave.jpg",
"name": "The Baz"
}
]
}
```
/// info
๐ โ `images` ๐ ๐ โ๏ธ ๐ ๐ผ ๐.
///
## ๐ ๐ฆ ๐ท
๐ ๐ช ๐ฌ ๐ฒ ๐ ๐ฆ ๐ท:
{* ../../docs_src/body_nested_models/tutorial007.py hl[9,14,20,23,27] *}
/// info
๐ โ `Offer` โ๏ธ ๐ `Item`โ, โ ๐ โ๏ธ ๐ฆ ๐ `Image`โ
///
## ๐ช ๐ ๐
๐ฅ ๐ ๐ ๐ฒ ๐ป ๐ช ๐ โ ๐ป `array` (๐ `list`), ๐ ๐ช ๐ฃ ๐ ๐ข ๐ข, ๐ Pydantic ๐ท:
```Python
images: List[Image]
```
โ๏ธ ๐ 3๏ธโฃ.9๏ธโฃ & ๐:
```Python
images: list[Image]
```
:
{* ../../docs_src/body_nested_models/tutorial008.py hl[15] *}
## ๐จโ๐จ ๐โ๐ฆบ ๐
& ๐ ๐ค ๐จโ๐จ ๐โ๐ฆบ ๐.
๐ฌ ๐ ๐:
๐ ๐ซ ๐ซ ๐ค ๐ ๐ ๐จโ๐จ ๐โ๐ฆบ ๐ฅ ๐ ๐ท ๐ โฎ๏ธ `dict` โฉ๏ธ Pydantic ๐ท.
โ๏ธ ๐ ๐ซ โ๏ธ ๐ ๐ ๐ซ ๐ฏโโ๏ธ, ๐จ #๏ธโฃ ๐ ๐ & ๐ ๐ข ๐ ๐ ๐ป ๐โโ๏ธ.
## ๐ช โ `dict`โ
๐ ๐ช ๐ฃ ๐ช `dict` โฎ๏ธ ๐ ๐ & ๐ฒ ๐ ๐.
๐ต โ๏ธ ๐ญ โช โซ๏ธโ โ ๐/๐ข ๐ (๐ ๐ผ โฎ๏ธ Pydantic ๐ท).
๐ ๐ โ ๐ฅ ๐ ๐ ๐จ ๐ ๐ ๐ ๐ซ โช ๐ญ.
---
๐ โ ๐ผ ๐โ ๐ ๐ โ๏ธ ๐ ๐ ๐, โ
`int`.
๐ โซ๏ธโ ๐ฅ ๐ ๐ ๐ฅ.
๐ ๐ผ, ๐ ๐ ๐ซ ๐ `dict` ๐ โซ๏ธ โ๏ธ `int` ๐ โฎ๏ธ `float` ๐ฒ:
{* ../../docs_src/body_nested_models/tutorial009.py hl[9] *}
/// tip
โ๏ธ ๐คฏ ๐ ๐ป ๐ด ๐โ๐ฆบ `str` ๐.
โ๏ธ Pydantic โ๏ธ ๐ง ๐ฝ ๐ ๏ธ.
๐ โ ๐, โ๏ธ ๐ ๐ ๏ธ ๐ฉโ๐ป ๐ช ๐ด ๐จ ๐ป ๐, ๐ ๐ ๐ป ๐ ๐ ๐ข, Pydantic ๐ ๐ ๐ซ & โ ๐ซ.
& `dict` ๐ ๐จ `weights` ๐ ๐ค โ๏ธ `int` ๐ & `float` ๐ฒ.
///
## ๐
โฎ๏ธ **FastAPI** ๐ โ๏ธ ๐ ๐ช ๐ Pydantic ๐ท, โช ๐ง ๐ ๐ ๐
, ๐ & ๐.
โ๏ธ โฎ๏ธ ๐ ๐ฐ:
* ๐จโ๐จ ๐โ๐ฆบ (๐ ๏ธ ๐ โ)
* ๐ฝ ๐ ๏ธ (.โ.. โ / ๐ ๏ธ)
* ๐ฝ ๐ฌ
* ๐ ๐งพ
* ๐ง ๐ฉบ