mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
✨ Compatible with pydantic 2.0 using the pydantic compatibility layer provided by nonebot
This commit is contained in:
@@ -14,11 +14,11 @@ router = APIRouter(prefix="/menu")
|
||||
@router.get(
|
||||
"/get_menus",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[list[MenuData]],
|
||||
response_model=Result[MenuData],
|
||||
response_class=JSONResponse,
|
||||
description="获取菜单列表",
|
||||
)
|
||||
async def _() -> Result[list[MenuData]]:
|
||||
async def _() -> Result[MenuData]:
|
||||
try:
|
||||
return Result.ok(menu_manage.get_menus(), "拿到菜单了哦!")
|
||||
except Exception as e:
|
||||
|
||||
@@ -56,7 +56,7 @@ class MenuManage:
|
||||
|
||||
def save(self):
|
||||
self.file.parent.mkdir(parents=True, exist_ok=True)
|
||||
temp = [menu.dict() for menu in self.menu]
|
||||
temp = [menu.to_dict() for menu in self.menu]
|
||||
with self.file.open("w", encoding="utf8") as f:
|
||||
json.dump(temp, f, ensure_ascii=False, indent=4)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from nonebot.compat import model_dump
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -13,6 +14,9 @@ class MenuItem(BaseModel):
|
||||
default: bool = False
|
||||
"""默认选中"""
|
||||
|
||||
def to_dict(self, **kwargs):
|
||||
return model_dump(self, **kwargs)
|
||||
|
||||
|
||||
class MenuData(BaseModel):
|
||||
bot_type: str = "zhenxun"
|
||||
|
||||
Reference in New Issue
Block a user