feat: 添加代码生成功能
This commit is contained in:
51
templates/python/schemas.py.jinja
Normal file
51
templates/python/schemas.py.jinja
Normal file
@@ -0,0 +1,51 @@
|
||||
# _*_ coding : UTF-8 _*_
|
||||
# @Time : {{ current_time }}
|
||||
# @UpdateTime : {{ current_time }}
|
||||
# @Author : {{ author }}
|
||||
# @File : {{ table_name }}.py
|
||||
# @Comment : 本程序用于生成{{ table_comment }}参数和响应模型
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
from pydantic.alias_generators import to_snake
|
||||
from schemas.common import BaseResponse, ListQueryResult
|
||||
|
||||
class {{ class_name }}Info(BaseModel):
|
||||
"""{{ description }}信息"""
|
||||
model_config = ConfigDict(alias_generator=to_snake, populate_by_name=True)
|
||||
{% for column in columns %}
|
||||
{{ column.python_name }}: {% if not column.is_required %}Optional[{% endif %}{{ column.python_type }}{% if not column.is_required %}]{% endif %} = Field(
|
||||
{% if column.default is not none %}default={{ column.default }}, {% endif %}title="{{ column.column_comment }}"
|
||||
)
|
||||
{% endfor %}
|
||||
|
||||
class Add{{ class_name }}Params(BaseModel):
|
||||
"""新增{{ description }}参数"""
|
||||
model_config = ConfigDict(alias_generator=to_snake, populate_by_name=True)
|
||||
{% for column in columns if column.is_insert %}
|
||||
{{ column.python_name }}: {% if not column.is_required %}Optional[{% endif %}{{ column.python_type }}{% if not column.is_required %}]{% endif %} = Field(
|
||||
{% if column.default is not none %}default={{ column.default }}, {% endif %}title="{{ column.column_comment }}"
|
||||
)
|
||||
{% endfor %}
|
||||
|
||||
class Update{{ class_name }}Params(BaseModel):
|
||||
"""更新{{ description }}参数"""
|
||||
model_config = ConfigDict(alias_generator=to_snake, populate_by_name=True)
|
||||
{% for column in columns if column.is_edit %}
|
||||
{{ column.python_name }}: {% if not column.is_required %}Optional[{% endif %}{{ column.python_type }}{% if not column.is_required %}]{% endif %} = Field(
|
||||
{% if column.default is not none %}default={{ column.default }}, {% endif %}title="{{ column.column_comment }}"
|
||||
)
|
||||
{% endfor %}
|
||||
|
||||
class Get{{ class_name }}InfoResponse(BaseResponse):
|
||||
"""获取{{ description }}信息响应"""
|
||||
data: {{ class_name }}Info = Field(None, title="{{ table_comment }}信息")
|
||||
|
||||
class Get{{ class_name }}InfoListResult(ListQueryResult):
|
||||
"""获取{{ description }}信息列表响应结果"""
|
||||
result: List[{{ class_name }}Info] = Field(None, title="{{ table_comment }}信息列表")
|
||||
|
||||
class Get{{ class_name }}InfoListResponse(BaseResponse):
|
||||
"""获取{{ description }}信息列表响应"""
|
||||
data: Get{{ class_name }}InfoListResult = Field(None, title="{{ table_comment }}信息列表")
|
||||
Reference in New Issue
Block a user