File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ from typing import List , Optional
2+
3+ from fastapi import Form
4+ from pydantic import BaseModel
5+
6+
7+ class Todo (BaseModel ):
8+ id : Optional [int ]
9+ item : str
10+
11+ @classmethod
12+ def as_form (
13+ cls ,
14+ item : str = Form (...)
15+ ):
16+ return cls (item = item )
17+
18+ class Config :
19+ schema_extra = {
20+ "example" : {
21+ "id" : 1 ,
22+ "item" : "Example schema!"
23+ }
24+ }
25+
26+
27+ class TodoItem (BaseModel ):
28+ item : str
29+
30+ class Config :
31+ schema_extra = {
32+ "example" : {
33+ "item" : "Read the next chapter of the book"
34+ }
35+ }
36+
37+
38+ class TodoItems (BaseModel ):
39+ todos : List [TodoItem ]
40+
41+ class Config :
42+ schema_extra = {
43+ "example" : {
44+ "todos" : [
45+ {
46+ "item" : "Example schema 1!"
47+ },
48+ {
49+ "item" : "Example schema 2!"
50+ }
51+ ]
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments