- TemplateRepo/SqlTemplateRepo(list/create/delete,owner stub 过滤,只 flush 端点 commit) - schemas/templates.py(title/body min_length=1→422)+ routers/templates.py(删不存在→404)+ main 注册 - 单测:repo CRUD/owner 隔离/frozen + 端点 201/列出/204/422×2/404
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""模板库端点的请求/响应 schema(F3 / 契约 §F3)。
|
||
|
||
snake_case;前端经 OpenAPI 生成 TS 类型消费。改字段 → 前端必须 `pnpm gen:api`。
|
||
单用户本地版:作者保存/复用提示词模板,可一键填入生成器的 brief/text。
|
||
`title`/`body` 非空(`min_length=1`,空 → FastAPI 422)。`category`/`tool_key` 可选。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import uuid
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class TemplateCreateRequest(BaseModel):
|
||
"""POST /templates:新建一条提示词模板。"""
|
||
|
||
title: str = Field(min_length=1, description="模板标题")
|
||
body: str = Field(min_length=1, description="模板正文(一键填入生成器的 brief/text)")
|
||
category: str | None = Field(default=None, description="可选分类")
|
||
tool_key: str | None = Field(default=None, description="可选关联生成器(NULL=通用)")
|
||
|
||
|
||
class TemplateResponse(BaseModel):
|
||
"""模板视图(列出/创建后回显;snake_case)。"""
|
||
|
||
id: uuid.UUID
|
||
title: str
|
||
body: str
|
||
category: str | None = None
|
||
tool_key: str | None = None
|