You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
from pydantic import BaseModel , Field , field_validator
from app . api . v1 . module_energy . variable . schema import VariableItemSchema
class TemplateChapterRuleSchema ( BaseModel ) :
""" 模板章节规则配置项。 """
id : int | None = Field ( default = None , ge = 1 , description = " 章节规则标注ID, 存在则更新, 不传则新增 " )
chapter_name : str = Field ( . . . , min_length = 1 , max_length = 128 , description = " 章节名称 " )
chapter_order : int = Field ( default = 999 , ge = 0 , description = " 章节排序 " )
rule_id : int = Field ( . . . , ge = 1 , description = " 关联规则ID " )
description : str | None = Field ( default = None , max_length = 500 , description = " 描述 " )
@field_validator ( " chapter_name " )
@classmethod
def validate_chapter_name ( cls , value : str ) - > str :
value = value . strip ( )
if not value :
raise ValueError ( " 章节名称不能为空 " )
return value
class TemplateConfigSaveSchema ( BaseModel ) :
""" 模板章节规则和变量关联统一保存模型。 """
template_id : int = Field ( . . . , ge = 1 , description = " 模板ID " )
chapters : list [ TemplateChapterRuleSchema ] = Field ( default_factory = list , description = " 章节规则标注列表 " )
variables : list [ VariableItemSchema ] = Field ( default_factory = list , description = " 变量关联列表 " )