-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.py
40 lines (32 loc) · 1.26 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pydantic import BaseModel
from typing import List
# ------------------------------------------------------------------------------
# Schema
# ==============================================================================
# ⚠️ Pydantic for schema (model) and validation. Prune anything that isn't used.
#
# Notes
# -----
# 1. Decleration order is important!
# - Running `uvicorn` with `Item` below `ToDo` throws an error.
# 2. Slight deviations from the book (where it makes sense).
# 3. You can access attributes by dot notation.
#
# Bruno
# -----
# We'll use Bruno instead of `model_config` within the `class`es. It's a far nicer
# experience to view the documentation there. See `/chapter_02` for more info.
#
# - Our response data won't have examples with Bruno.
# - You can figure it out by looking at the `json` responses.
# Model ------------------------------------------------------------------------
# These are what we'll use to validate our `json` requests.
class ToDo(BaseModel):
id: int
item: str
class ToDoItem(BaseModel):
item: str
# Return type ------------------------------------------------------------------
# These are what we'll use to validate our `json` responses, if needed.
class ToDoItems(BaseModel):
todos: List[ToDoItem]