fastgenerateapi 0.0.28__py2.py3-none-any.whl → 1.1.6__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastgenerateapi might be problematic. Click here for more details.
- fastgenerateapi/__init__.py +2 -2
- fastgenerateapi/__version__.py +1 -1
- fastgenerateapi/api_view/base_view.py +17 -7
- fastgenerateapi/api_view/create_view.py +1 -1
- fastgenerateapi/api_view/delete_filter_view.py +1 -1
- fastgenerateapi/api_view/delete_tree_view.py +3 -3
- fastgenerateapi/api_view/delete_view.py +3 -3
- fastgenerateapi/api_view/get_all_view.py +10 -8
- fastgenerateapi/api_view/get_one_view.py +1 -1
- fastgenerateapi/api_view/get_relation_view.py +1 -1
- fastgenerateapi/api_view/get_tree_view.py +1 -1
- fastgenerateapi/api_view/mixin/base_mixin.py +11 -7
- fastgenerateapi/api_view/mixin/dbmodel_mixin.py +30 -20
- fastgenerateapi/api_view/mixin/response_mixin.py +68 -38
- fastgenerateapi/api_view/mixin/tool_mixin.py +1 -357
- fastgenerateapi/api_view/mixin/utils/__init__.py +0 -0
- fastgenerateapi/api_view/mixin/utils/docx_util.py +399 -0
- fastgenerateapi/api_view/mixin/utils/file_util.py +30 -0
- fastgenerateapi/api_view/mixin/utils/pdf_util.py +76 -0
- fastgenerateapi/api_view/mixin/utils/xlsx_util.py +336 -0
- fastgenerateapi/api_view/mixin/utils/zip_util.py +50 -0
- fastgenerateapi/api_view/switch_view.py +2 -2
- fastgenerateapi/api_view/update_relation_view.py +3 -3
- fastgenerateapi/api_view/update_view.py +1 -1
- fastgenerateapi/cache/cache_decorator.py +1 -1
- fastgenerateapi/controller/filter_controller.py +68 -26
- fastgenerateapi/controller/router_controller.py +9 -9
- fastgenerateapi/controller/rpc_controller.py +1 -1
- fastgenerateapi/controller/ws_controller.py +1 -1
- fastgenerateapi/deps/filter_params_deps.py +34 -4
- fastgenerateapi/deps/paginator_deps.py +4 -4
- fastgenerateapi/deps/tree_params_deps.py +4 -4
- fastgenerateapi/fastapi_utils/__init__.py +0 -0
- fastgenerateapi/fastapi_utils/all.py +5 -0
- fastgenerateapi/fastapi_utils/param_utils.py +37 -0
- fastgenerateapi/fastapi_utils/response_utils.py +344 -0
- fastgenerateapi/model/__init__.py +0 -0
- fastgenerateapi/model/base_model.py +56 -0
- fastgenerateapi/my_fields/enum_field.py +5 -5
- fastgenerateapi/my_fields/validator.py +60 -0
- fastgenerateapi/pydantic_utils/base_model.py +46 -20
- fastgenerateapi/pydantic_utils/base_settings.py +16 -0
- fastgenerateapi/pydantic_utils/json_encoders.py +2 -1
- fastgenerateapi/schemas_factory/common_function.py +1 -1
- fastgenerateapi/schemas_factory/common_schema_factory.py +4 -4
- fastgenerateapi/schemas_factory/create_schema_factory.py +4 -4
- fastgenerateapi/schemas_factory/filter_schema_factory.py +6 -6
- fastgenerateapi/schemas_factory/get_all_schema_factory.py +5 -5
- fastgenerateapi/schemas_factory/get_one_schema_factory.py +4 -3
- fastgenerateapi/schemas_factory/get_relation_schema_factory.py +3 -3
- fastgenerateapi/schemas_factory/get_tree_schema_factory.py +3 -3
- fastgenerateapi/schemas_factory/response_factory.py +3 -3
- fastgenerateapi/schemas_factory/sql_get_all_schema_factory.py +3 -3
- fastgenerateapi/schemas_factory/update_schema_factory.py +4 -4
- fastgenerateapi/settings/__init__.py +6 -0
- fastgenerateapi/settings/all_settings.py +91 -0
- fastgenerateapi/settings/{settings.py → app_settings.py} +9 -9
- fastgenerateapi/settings/db_settings.py +69 -0
- fastgenerateapi/settings/file_settings.py +24 -0
- fastgenerateapi/settings/jwt_settings.py +23 -0
- fastgenerateapi/settings/otlp_settings.py +69 -0
- fastgenerateapi/settings/redis_settings.py +16 -0
- fastgenerateapi/settings/sms_settings.py +25 -0
- fastgenerateapi/settings/system_settings.py +30 -0
- fastgenerateapi/utils/auto_discover.py +61 -0
- fastgenerateapi/utils/file_utils.py +76 -0
- fastgenerateapi/utils/pwd_utils.py +49 -0
- fastgenerateapi/utils/ramdom_utils.py +48 -0
- fastgenerateapi/utils/snowflake.py +23 -20
- fastgenerateapi/utils/str_util.py +120 -0
- fastgenerateapi/utils/swagger_to_js.py +26 -0
- {fastgenerateapi-0.0.28.dist-info → fastgenerateapi-1.1.6.dist-info}/METADATA +61 -24
- fastgenerateapi-1.1.6.dist-info/RECORD +109 -0
- {fastgenerateapi-0.0.28.dist-info → fastgenerateapi-1.1.6.dist-info}/WHEEL +1 -1
- {fastgenerateapi-0.0.28.dist-info → fastgenerateapi-1.1.6.dist-info}/top_level.txt +1 -0
- script/__init__.py +2 -0
- fastgenerateapi/settings/register_settings.py +0 -6
- fastgenerateapi/utils/parse_str.py +0 -36
- fastgenerateapi-0.0.28.dist-info/RECORD +0 -82
- {fastgenerateapi-0.0.28.dist-info → fastgenerateapi-1.1.6.dist-info}/LICENSE +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import importlib
|
|
2
|
-
from typing import List
|
|
2
|
+
from typing import List, Optional
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel as PydanticBaseModel,
|
|
4
|
+
from pydantic import BaseModel as PydanticBaseModel, BaseConfig, Field, ConfigDict
|
|
5
5
|
|
|
6
6
|
from fastgenerateapi.pydantic_utils.json_encoders import JSON_ENCODERS
|
|
7
|
-
from fastgenerateapi.settings.
|
|
7
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
8
8
|
|
|
9
9
|
try:
|
|
10
10
|
module_path, class_name = settings.app_settings.ALIAS_GENERATOR.rsplit('.', maxsplit=1)
|
|
@@ -14,28 +14,54 @@ except Exception:
|
|
|
14
14
|
alias_generator = None
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
class
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
class ModelConfig(ConfigDict):
|
|
18
|
+
|
|
19
|
+
def __init__(self, seq=None, **kwargs):
|
|
20
|
+
default_kwargs = {
|
|
21
|
+
"json_encoders": JSON_ENCODERS,
|
|
22
|
+
"extra": "ignore", # v1 ignore v2 版本没有 Extra.ignore
|
|
23
|
+
# orm_mode=True, # v1 版本
|
|
24
|
+
"from_attributes": True, # v2 版本
|
|
25
|
+
# allow_population_by_field_name=True, # v1 版本
|
|
26
|
+
"populate_by_name": True, # v2 版本,支持原本的属性和驼峰命名
|
|
27
|
+
"alias_generator": alias_generator,
|
|
28
|
+
}
|
|
29
|
+
default_kwargs.update(kwargs)
|
|
30
|
+
super().__init__(seq=seq, **default_kwargs)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
json_encoders=JSON_ENCODERS,
|
|
35
|
+
extra="ignore", # v1 ignore v2 版本没有 Extra.ignore
|
|
36
|
+
# orm_mode=True, # v1 版本
|
|
37
|
+
from_attributes=True, # v2 版本
|
|
38
|
+
# allow_population_by_field_name=True, # v1 版本
|
|
39
|
+
populate_by_name=True, # v2 版本,支持原本的属性和驼峰命名
|
|
40
|
+
alias_generator=alias_generator,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# class Config(BaseConfig):
|
|
45
|
+
# json_encoders = JSON_ENCODERS
|
|
46
|
+
# extra = "ignore" # v1 ignore v2 版本没有 Extra.ignore
|
|
47
|
+
# orm_mode = True # v1 版本
|
|
48
|
+
# from_attributes = True # v2 版本
|
|
49
|
+
# allow_population_by_field_name = True # v1 版本
|
|
50
|
+
# populate_by_name = True # v2 版本,支持原本的属性和驼峰命名
|
|
51
|
+
# alias_generator = alias_generator
|
|
25
52
|
|
|
26
53
|
|
|
27
54
|
class BaseModel(PydanticBaseModel):
|
|
28
|
-
|
|
29
|
-
...
|
|
55
|
+
model_config = model_config
|
|
30
56
|
|
|
31
57
|
|
|
32
|
-
class
|
|
33
|
-
|
|
58
|
+
class IdList(BaseModel):
|
|
59
|
+
id_list: List[str] = Field([], description="id数组")
|
|
34
60
|
|
|
35
61
|
|
|
36
|
-
class
|
|
37
|
-
|
|
62
|
+
class EmptyPydantic(BaseModel):
|
|
63
|
+
...
|
|
64
|
+
|
|
38
65
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# extra = Extra.ignore
|
|
66
|
+
class SearchPydantic(BaseModel):
|
|
67
|
+
search: Optional[str] = Field(None, description="搜索")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
# 尝试导入新版本的BaseSettings
|
|
5
|
+
from pydantic_settings import BaseSettings
|
|
6
|
+
except ImportError:
|
|
7
|
+
try:
|
|
8
|
+
# 如果失败,尝试导入旧版本的BaseSettings
|
|
9
|
+
from pydantic import BaseSettings
|
|
10
|
+
except ImportError:
|
|
11
|
+
# 如果两种方式都失败,抛出明确的错误信息
|
|
12
|
+
raise ImportError(
|
|
13
|
+
"Could not import BaseSettings. "
|
|
14
|
+
"Please install either pydantic<2.0 (for older version) or pydantic-settings (for newer version)."
|
|
15
|
+
)
|
|
16
|
+
|
|
@@ -41,7 +41,8 @@ common_format_with_s_time = new_time_type("COMMON_FORMAT_WITH_S_TIME", format_st
|
|
|
41
41
|
JSON_ENCODERS = {
|
|
42
42
|
time: lambda v: v.strftime(TIME_FORMAT_TIME_COMMON),
|
|
43
43
|
date: lambda v: v.strftime(DATE_FORMAT_COMMON),
|
|
44
|
-
datetime: lambda v: v.strftime(DATETIME_FORMAT_COMMON),
|
|
44
|
+
# datetime: lambda v: v.strftime(DATETIME_FORMAT_COMMON),
|
|
45
|
+
datetime: lambda v: int(v.timestamp() * 1000),
|
|
45
46
|
|
|
46
47
|
# special date type
|
|
47
48
|
common_format_datetime: lambda v: v.strftime(v.format_str),
|
|
@@ -5,7 +5,7 @@ from pydantic.fields import FieldInfo
|
|
|
5
5
|
from tortoise import Model
|
|
6
6
|
|
|
7
7
|
from fastgenerateapi.api_view.mixin.dbmodel_mixin import DBModelMixin
|
|
8
|
-
from fastgenerateapi.settings.
|
|
8
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def get_field_info(value, description="", default_field_type=None) -> (Type, FieldInfo):
|
|
@@ -4,10 +4,10 @@ from pydantic import create_model
|
|
|
4
4
|
from tortoise import Model
|
|
5
5
|
|
|
6
6
|
from fastgenerateapi.data_type.data_type import T
|
|
7
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
7
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
8
8
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta, \
|
|
9
9
|
get_validate_dict_from_fields
|
|
10
|
-
from fastgenerateapi.settings.
|
|
10
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def common_schema_factory(
|
|
@@ -65,9 +65,9 @@ def common_schema_factory(
|
|
|
65
65
|
schema_field_dict = {field: all_fields_info[field] for field in all_fields}
|
|
66
66
|
validators_dict = get_validate_dict_from_fields(schema_field_dict)
|
|
67
67
|
schema: Type[T] = create_model(
|
|
68
|
-
|
|
68
|
+
name,
|
|
69
69
|
**schema_field_dict,
|
|
70
|
-
__config__=
|
|
70
|
+
__config__=model_config,
|
|
71
71
|
__validators__=validators_dict,
|
|
72
72
|
)
|
|
73
73
|
return schema
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from typing import Type, Union, Optional
|
|
2
2
|
|
|
3
|
-
from fastgenerateapi.settings.
|
|
3
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
4
4
|
|
|
5
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
5
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
from tortoise import Model
|
|
8
8
|
|
|
@@ -75,9 +75,9 @@ def create_schema_factory(
|
|
|
75
75
|
schema_field_dict = {field: all_fields_info[field] for field in all_fields}
|
|
76
76
|
validators_dict = get_validate_dict_from_fields(schema_field_dict)
|
|
77
77
|
schema: Type[T] = create_model(
|
|
78
|
-
|
|
78
|
+
schema_name,
|
|
79
79
|
**schema_field_dict,
|
|
80
|
-
__config__=
|
|
80
|
+
__config__=model_config,
|
|
81
81
|
__validators__=validators_dict,
|
|
82
82
|
)
|
|
83
83
|
return schema
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from typing import Type, Union
|
|
2
2
|
|
|
3
3
|
from fastapi import Query
|
|
4
|
-
from fastgenerateapi.pydantic_utils.base_model import QueryConfig
|
|
5
4
|
from pydantic import BaseModel, create_model
|
|
6
5
|
from pydantic.fields import FieldInfo
|
|
7
6
|
|
|
7
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
8
8
|
from fastgenerateapi.api_view.mixin.dbmodel_mixin import DBModelMixin
|
|
9
9
|
from fastgenerateapi.controller.filter_controller import BaseFilter
|
|
10
10
|
from tortoise import Model
|
|
@@ -21,18 +21,18 @@ def filter_schema_factory(model_class: Type[Model], fields: list[str, tuple[str,
|
|
|
21
21
|
field_info = BaseFilter(field_info)
|
|
22
22
|
f = field_info.filter_field
|
|
23
23
|
t = field_info.field_type
|
|
24
|
-
|
|
24
|
+
description = DBModelMixin.get_field_description(model_class, field_info.model_field)
|
|
25
25
|
model_fields.update({
|
|
26
26
|
f: (
|
|
27
27
|
Union[t, str],
|
|
28
28
|
FieldInfo(
|
|
29
|
-
title=f"{
|
|
30
|
-
default=Query(""),
|
|
31
|
-
description=f"{
|
|
29
|
+
title=f"{description}",
|
|
30
|
+
default=Query("", description=description),
|
|
31
|
+
description=f"{description}"
|
|
32
32
|
))
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
filter_params_model: Type[BaseModel] = create_model(
|
|
35
|
+
filter_params_model: Type[BaseModel] = create_model("CommonFilterParams", **model_fields, __config__=model_config)
|
|
36
36
|
|
|
37
37
|
return filter_params_model
|
|
38
38
|
|
|
@@ -6,9 +6,9 @@ from tortoise import Model
|
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
|
|
8
8
|
from fastgenerateapi.data_type.data_type import T
|
|
9
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
9
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
10
10
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta
|
|
11
|
-
from fastgenerateapi.settings.
|
|
11
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def get_all_schema_factory(
|
|
@@ -77,7 +77,7 @@ def get_all_schema_factory(
|
|
|
77
77
|
|
|
78
78
|
schema_name = name if name else model_class.__name__ + "GetAllSchema"
|
|
79
79
|
schema: Type[T] = create_model(
|
|
80
|
-
|
|
80
|
+
schema_name, **{field: all_fields_info[field] for field in all_fields}, __config__=model_config)
|
|
81
81
|
return schema
|
|
82
82
|
|
|
83
83
|
|
|
@@ -92,7 +92,7 @@ def get_list_schema_factory(schema_cls: Type[T] = None) -> Type[T]:
|
|
|
92
92
|
settings.app_settings.LIST_RESPONSE_FIELD: (Optional[List], FieldInfo(default=[], description="数据返回")),
|
|
93
93
|
}
|
|
94
94
|
name = "GetListSchema" + str(time.time())
|
|
95
|
-
schema: Type[T] = create_model(
|
|
95
|
+
schema: Type[T] = create_model(name, **fields, __config__=model_config)
|
|
96
96
|
return schema
|
|
97
97
|
|
|
98
98
|
|
|
@@ -108,7 +108,7 @@ def get_page_schema_factory(schema_cls: Type[T] = None) -> Type[T]:
|
|
|
108
108
|
else:
|
|
109
109
|
fields.update({settings.app_settings.LIST_RESPONSE_FIELD: (Optional[List], FieldInfo(default=[], description="数据返回"))})
|
|
110
110
|
name = "GetPageSchema" + str(time.time())
|
|
111
|
-
schema: Type[T] = create_model(
|
|
111
|
+
schema: Type[T] = create_model(name, **fields, __config__=model_config)
|
|
112
112
|
return schema
|
|
113
113
|
|
|
114
114
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from typing import Type, Optional, Union
|
|
2
2
|
|
|
3
|
-
from fastgenerateapi.settings.
|
|
3
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
4
4
|
|
|
5
|
-
from fastgenerateapi.pydantic_utils.base_model import Config
|
|
5
|
+
# from fastgenerateapi.pydantic_utils.base_model import Config
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
from tortoise import Model
|
|
8
8
|
|
|
9
9
|
from fastgenerateapi.data_type.data_type import T
|
|
10
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
10
11
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta
|
|
11
12
|
|
|
12
13
|
|
|
@@ -71,7 +72,7 @@ def get_one_schema_factory(
|
|
|
71
72
|
|
|
72
73
|
schema_name = name if name else model_class.__name__ + "GetOneSchema"
|
|
73
74
|
schema: Type[T] = create_model(
|
|
74
|
-
|
|
75
|
+
schema_name, **{field: all_fields_info[field] for field in all_fields}, __config__=model_config)
|
|
75
76
|
return schema
|
|
76
77
|
|
|
77
78
|
|
|
@@ -6,9 +6,9 @@ from tortoise import Model
|
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
|
|
8
8
|
from fastgenerateapi.data_type.data_type import T
|
|
9
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
9
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
10
10
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta
|
|
11
|
-
from fastgenerateapi.settings.
|
|
11
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def get_relation_schema_factory(
|
|
@@ -64,7 +64,7 @@ def get_relation_schema_factory(
|
|
|
64
64
|
|
|
65
65
|
schema_name = name if name else model_class.__name__ + "GetRelationSchema"
|
|
66
66
|
schema: Type[T] = create_model(
|
|
67
|
-
|
|
67
|
+
schema_name, **{field: all_fields_info[field] for field in all_fields}, __config__=model_config)
|
|
68
68
|
|
|
69
69
|
return schema
|
|
70
70
|
|
|
@@ -6,9 +6,9 @@ from tortoise import Model
|
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
|
|
8
8
|
from fastgenerateapi.data_type.data_type import T
|
|
9
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
9
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
10
10
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta
|
|
11
|
-
from fastgenerateapi.settings.
|
|
11
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def get_tree_schema_factory(
|
|
@@ -78,7 +78,7 @@ def get_tree_schema_factory(
|
|
|
78
78
|
...
|
|
79
79
|
|
|
80
80
|
schema: Type[T] = create_model(
|
|
81
|
-
|
|
81
|
+
schema_name, **{field: all_fields_info[field] for field in all_fields}, __config__=model_config)
|
|
82
82
|
|
|
83
83
|
return schema
|
|
84
84
|
|
|
@@ -5,8 +5,8 @@ from pydantic import create_model
|
|
|
5
5
|
from pydantic.fields import FieldInfo
|
|
6
6
|
|
|
7
7
|
from fastgenerateapi.data_type.data_type import T
|
|
8
|
-
from fastgenerateapi.pydantic_utils.base_model import BaseModel,
|
|
9
|
-
from fastgenerateapi.settings.
|
|
8
|
+
from fastgenerateapi.pydantic_utils.base_model import BaseModel, model_config
|
|
9
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def response_factory(schema_cls: Union[Type[T], BaseModel, None] = None, name: str = "") -> Type[T]:
|
|
@@ -36,6 +36,6 @@ def response_factory(schema_cls: Union[Type[T], BaseModel, None] = None, name: s
|
|
|
36
36
|
name = schema_cls.__name__ + name + "Response" + str(time.time())
|
|
37
37
|
except:
|
|
38
38
|
name = "CommonResponse"
|
|
39
|
-
schema: Type[T] = create_model(
|
|
39
|
+
schema: Type[T] = create_model(name, **fields, __config__=model_config)
|
|
40
40
|
|
|
41
41
|
return schema
|
|
@@ -7,9 +7,9 @@ from pydantic import create_model
|
|
|
7
7
|
|
|
8
8
|
from fastgenerateapi.data_type.data_type import T
|
|
9
9
|
from fastgenerateapi.data_type.mysql_data_type import mysql_data_type
|
|
10
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
10
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
11
11
|
from fastgenerateapi.schemas_factory.common_function import get_dict_from_model_fields, get_dict_from_pydanticmeta
|
|
12
|
-
from fastgenerateapi.settings.
|
|
12
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def sql_get_all_schema_factory(field_info_list, include_fields, exclude_fields) -> Optional[Type[T]]:
|
|
@@ -41,7 +41,7 @@ def sql_get_all_schema_factory(field_info_list, include_fields, exclude_fields)
|
|
|
41
41
|
table_name = field_info_list[0].get("TABLE_NAME") if field_info_list[0] else str(time.time())
|
|
42
42
|
name = table_name + "GetAllSchema"
|
|
43
43
|
schema: Type[T] = create_model(
|
|
44
|
-
|
|
44
|
+
name, **{field: all_fields_info[field] for field in all_fields}, __config__=model_config)
|
|
45
45
|
return schema
|
|
46
46
|
|
|
47
47
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from typing import Type, Union, Optional
|
|
2
2
|
|
|
3
|
-
from fastgenerateapi.settings.
|
|
3
|
+
from fastgenerateapi.settings.all_settings import settings
|
|
4
4
|
|
|
5
|
-
from fastgenerateapi.pydantic_utils.base_model import
|
|
5
|
+
from fastgenerateapi.pydantic_utils.base_model import model_config
|
|
6
6
|
from pydantic import create_model
|
|
7
7
|
from tortoise import Model
|
|
8
8
|
|
|
@@ -75,9 +75,9 @@ def update_schema_factory(
|
|
|
75
75
|
schema_field_dict = {field: all_fields_info[field] for field in all_fields}
|
|
76
76
|
validators_dict = get_validate_dict_from_fields(schema_field_dict)
|
|
77
77
|
schema: Type[T] = create_model(
|
|
78
|
-
|
|
78
|
+
schema_name,
|
|
79
79
|
**schema_field_dict,
|
|
80
|
-
__config__=
|
|
80
|
+
__config__=model_config,
|
|
81
81
|
__validators__=validators_dict,
|
|
82
82
|
)
|
|
83
83
|
return schema
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
|
|
4
|
+
from fastgenerateapi.settings.redis_settings import RedisSettings
|
|
5
|
+
from fastgenerateapi.settings.app_settings import AppSettings
|
|
6
|
+
from fastgenerateapi.settings.system_settings import SystemSettings
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SettingsModel(BaseModel):
|
|
10
|
+
# 应用配置
|
|
11
|
+
app_settings: AppSettings = AppSettings()
|
|
12
|
+
# 系统配置
|
|
13
|
+
system_settings: SystemSettings = SystemSettings()
|
|
14
|
+
# 缓存配置
|
|
15
|
+
redis_settings: RedisSettings = RedisSettings()
|
|
16
|
+
|
|
17
|
+
# pydantic v2 不支持 ModelField, v.type_
|
|
18
|
+
# @classmethod
|
|
19
|
+
# def generate_file(cls, path='./.env'):
|
|
20
|
+
# """
|
|
21
|
+
# 生成配置文件
|
|
22
|
+
# .env 会增加前缀
|
|
23
|
+
# .yaml 忽略前缀
|
|
24
|
+
# :param path: 可选 .env / application.yaml
|
|
25
|
+
# :return:
|
|
26
|
+
# """
|
|
27
|
+
# content = ''
|
|
28
|
+
# setting_models = cls.__fields__.copy()
|
|
29
|
+
# if path.__contains__('.env'):
|
|
30
|
+
# for k, v in setting_models.items():
|
|
31
|
+
# if issubclass(type(v), ModelField):
|
|
32
|
+
# sub_setting_class = v.type_
|
|
33
|
+
# content += f"[{sub_setting_class.__name__}]\n"
|
|
34
|
+
# fields = sub_setting_class.__fields__.copy()
|
|
35
|
+
# for k, v in fields.items():
|
|
36
|
+
# field_name = f'{sub_setting_class.Config.env_prefix}{k}'
|
|
37
|
+
# if v.field_info.description is None:
|
|
38
|
+
# content += f"{field_name}={v.default}\n"
|
|
39
|
+
# else:
|
|
40
|
+
# content += f"# {v.field_info.description}\n{field_name}={v.default}\n"
|
|
41
|
+
# content += "\n"
|
|
42
|
+
# elif path.__contains__('.yaml'):
|
|
43
|
+
# for k, v in setting_models.items():
|
|
44
|
+
# if issubclass(type(v), ModelField):
|
|
45
|
+
# sub_setting_class = v.type_
|
|
46
|
+
# content += f"{sub_setting_class.__name__}:\n"
|
|
47
|
+
# fields = sub_setting_class.__fields__.copy()
|
|
48
|
+
# for k, v in fields.items():
|
|
49
|
+
# content += f" {k}: {v.default}"
|
|
50
|
+
# if v.field_info.description is None:
|
|
51
|
+
# content += f"\n"
|
|
52
|
+
# else:
|
|
53
|
+
# content += f" # {v.field_info.description}\n"
|
|
54
|
+
# content += "\n"
|
|
55
|
+
# with open(file=path, mode='w', encoding='utf-8') as f:
|
|
56
|
+
# f.writelines(content)
|
|
57
|
+
#
|
|
58
|
+
# @classmethod
|
|
59
|
+
# @lru_cache
|
|
60
|
+
# def get_global_settings(cls, path: Union[types.Path, str, None] = '.env'):
|
|
61
|
+
# """
|
|
62
|
+
# get global settings and set into cache
|
|
63
|
+
# :param path: 可选 .env / application.yaml
|
|
64
|
+
# :return:
|
|
65
|
+
# """
|
|
66
|
+
# setting_models = cls.__fields__.copy()
|
|
67
|
+
#
|
|
68
|
+
# setting_dict = {}
|
|
69
|
+
# if str(path).__contains__('.env'):
|
|
70
|
+
# for k, v in setting_models.items():
|
|
71
|
+
# if issubclass(type(v), ModelField):
|
|
72
|
+
# sub_setting_class = v.type_
|
|
73
|
+
# setting_dict[k] = sub_setting_class(_env_file=str(path))
|
|
74
|
+
# elif str(path).__contains__('.yaml'):
|
|
75
|
+
# with open(path, 'r', encoding='utf-8') as file:
|
|
76
|
+
# data_dict = yaml.safe_load(file)
|
|
77
|
+
# for k, v in setting_models.items():
|
|
78
|
+
# if issubclass(type(v), ModelField):
|
|
79
|
+
# sub_setting_class = v.type_
|
|
80
|
+
# setting_dict[k] = sub_setting_class(**data_dict.get(sub_setting_class.__name__, {}))
|
|
81
|
+
#
|
|
82
|
+
# setting_data = cls(**setting_dict)
|
|
83
|
+
# global settings
|
|
84
|
+
# settings.app_settings = setting_data.app_settings
|
|
85
|
+
# settings.system_settings = setting_data.system_settings
|
|
86
|
+
# settings.redis_settings = setting_data.redis_settings
|
|
87
|
+
# return setting_data
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
settings = SettingsModel()
|
|
91
|
+
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
|
|
3
|
-
from pydantic import
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from fastgenerateapi.pydantic_utils.base_settings import BaseSettings
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class AppSettings(BaseSettings):
|
|
7
|
-
# 字段配置
|
|
8
|
-
ALIAS_GENERATOR: Optional[str] = Field(default="pydantic.
|
|
8
|
+
# 字段配置 老版本(pydantic.utils.to_lower_camel)
|
|
9
|
+
ALIAS_GENERATOR: Optional[str] = Field(default="pydantic.alias_generators.to_snake", description="序列化参数命名方法路径")
|
|
9
10
|
|
|
10
11
|
# 分页对应字段以及配置默认值
|
|
11
12
|
CURRENT_PAGE_FIELD: Optional[str] = Field(default="page", description="当前页字段")
|
|
@@ -32,9 +33,9 @@ class AppSettings(BaseSettings):
|
|
|
32
33
|
ROUTER_WHETHER_UNDERLINE_TO_STRIKE: Optional[bool] = Field(default=False, description="路由是否下划线转中划线")
|
|
33
34
|
ROUTER_WHETHER_ADD_SUFFIX: Optional[bool] = Field(default=True, description="增删改查路由是否添加后缀")
|
|
34
35
|
ROUTER_CREATE_SUFFIX_FIELD: Optional[str] = Field(default="create", description="创建路由后缀字段")
|
|
35
|
-
ROUTER_GET_ONE_SUFFIX_FIELD: Optional[str] = Field(default="
|
|
36
|
-
ROUTER_GET_ALL_SUFFIX_FIELD: Optional[str] = Field(default="
|
|
37
|
-
ROUTER_GET_TREE_SUFFIX_FIELD: Optional[str] = Field(default="
|
|
36
|
+
ROUTER_GET_ONE_SUFFIX_FIELD: Optional[str] = Field(default="detail", description="获取一个路由后缀字段") # get_one
|
|
37
|
+
ROUTER_GET_ALL_SUFFIX_FIELD: Optional[str] = Field(default="list", description="获取列表路由后缀字段") # get_all
|
|
38
|
+
ROUTER_GET_TREE_SUFFIX_FIELD: Optional[str] = Field(default="tree", description="获取树状数据路由后缀字段") # get_tree
|
|
38
39
|
ROUTER_UPDATE_SUFFIX_FIELD: Optional[str] = Field(default="update", description="修改路由后缀字段")
|
|
39
40
|
ROUTER_DELETE_SUFFIX_FIELD: Optional[str] = Field(default="delete", description="删除路由后缀字段")
|
|
40
41
|
ROUTER_RECURSION_DELETE_SUFFIX_FIELD: Optional[str] = Field(default="delete_tree", description="递归删除路由后缀字段")
|
|
@@ -82,8 +83,7 @@ class AppSettings(BaseSettings):
|
|
|
82
83
|
env_prefix = "APP_"
|
|
83
84
|
env_file = "./.env"
|
|
84
85
|
case_sensitive = True
|
|
86
|
+
extra = 'allow'
|
|
87
|
+
|
|
85
88
|
|
|
86
89
|
|
|
87
|
-
class SettingsModel(BaseModel):
|
|
88
|
-
# 系统配置
|
|
89
|
-
app_settings: AppSettings = AppSettings()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DBSettings(BaseSettings):
|
|
8
|
+
"""
|
|
9
|
+
Database Settings
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
TYPE: Optional[str] = Field(default='mysql', description="数据库类型")
|
|
13
|
+
HOST: Optional[str] = Field(default='127.0.0.1', description="数据库域名")
|
|
14
|
+
PORT: Optional[str] = Field(default='3306', description="数据库端口")
|
|
15
|
+
DATABASE: Optional[str] = Field(default='admin', description="数据库名")
|
|
16
|
+
USERNAME: Optional[str] = Field(default='root', description="数据库用户名")
|
|
17
|
+
PASSWORD: Optional[str] = Field(default='', description="数据库密码")
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def dsn(self):
|
|
21
|
+
return f"{self.TYPE.lower()}://{self.USERNAME}:{self.PASSWORD}@{self.HOST}:{self.PORT}/{self.DATABASE}"
|
|
22
|
+
|
|
23
|
+
class Config:
|
|
24
|
+
env_prefix = 'DB_'
|
|
25
|
+
env_file = "./.env"
|
|
26
|
+
case_sensitive = True
|
|
27
|
+
extra = 'allow'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class PostgresqlSettings(DBSettings):
|
|
31
|
+
"""
|
|
32
|
+
Postgresql Settings
|
|
33
|
+
"""
|
|
34
|
+
TYPE: Optional[str] = Field(default='postgres', description="数据库类型")
|
|
35
|
+
|
|
36
|
+
class Config:
|
|
37
|
+
env_prefix = 'Postgresql_'
|
|
38
|
+
env_file = "./.env"
|
|
39
|
+
case_sensitive = True
|
|
40
|
+
extra = 'allow'
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class MySQLSettings(DBSettings):
|
|
44
|
+
"""
|
|
45
|
+
MySQL Settings
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
class Config:
|
|
49
|
+
env_prefix = 'MYSQL_'
|
|
50
|
+
env_file = "./.env"
|
|
51
|
+
case_sensitive = True
|
|
52
|
+
extra = 'allow'
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class LocalSettings(DBSettings):
|
|
56
|
+
"""
|
|
57
|
+
MySQL Settings
|
|
58
|
+
"""
|
|
59
|
+
TYPE: str = Field(..., description="数据库类型")
|
|
60
|
+
|
|
61
|
+
class Config:
|
|
62
|
+
env_prefix = 'LOCAL_'
|
|
63
|
+
env_file = "./.env"
|
|
64
|
+
case_sensitive = True
|
|
65
|
+
extra = 'allow'
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FileServerSettings(BaseSettings):
|
|
8
|
+
"""
|
|
9
|
+
文件配置
|
|
10
|
+
"""
|
|
11
|
+
FILE_SERVER: Optional[str] = Field(default='http://localhost:8001', description="文件服务域名", title="file Server Domain")
|
|
12
|
+
FILE_URL: Optional[str] = Field(default='/static/', description="文件路径前缀", title="file url prefix")
|
|
13
|
+
FILE_ROOT: Optional[str] = Field(default='static', description="文件储存路径", title="file storage path")
|
|
14
|
+
|
|
15
|
+
class Config:
|
|
16
|
+
env_prefix = 'FileServer_'
|
|
17
|
+
env_file = "./.env"
|
|
18
|
+
case_sensitive = True
|
|
19
|
+
extra = 'allow'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class JWTSettings(BaseSettings):
|
|
8
|
+
"""
|
|
9
|
+
jwt配置
|
|
10
|
+
"""
|
|
11
|
+
SECRET_KEY: Optional[str] = Field(..., description="认证密钥", title="JWT SECRET KEY")
|
|
12
|
+
ALGORITHM: Optional[str] = Field(default='HS256', description="认证密钥", title="JWT ALGORITHM")
|
|
13
|
+
ACCESS_TOKEN_EXPIRE_MINUTES: Optional[int] = Field(default=30, description="过期时间 (分钟)", title="JWT Access Token")
|
|
14
|
+
REFRESH_TOKEN_EXPIRE_MINUTES: Optional[int] = Field(default=60, description="过期时间(分钟)", title="JWT Refresh Token")
|
|
15
|
+
|
|
16
|
+
class Config:
|
|
17
|
+
env_prefix = 'JWT_'
|
|
18
|
+
env_file = "./.env"
|
|
19
|
+
case_sensitive = True
|
|
20
|
+
extra = 'allow'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|