forked from TencentBlueKing/bk-plugin-framework-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializers.py
More file actions
19 lines (15 loc) · 762 Bytes
/
Copy pathserializers.py
File metadata and controls
19 lines (15 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from drf_spectacular.utils import extend_schema_serializer
from rest_framework import serializers
def standard_response_enveloper(serializer_class, many: bool = False):
"""统一响应包装器"""
component_name = "Enveloped{}{}".format(
serializer_class.__name__.replace("Serializer", ""),
"List" if many else "",
)
@extend_schema_serializer(many=False, component_name=component_name)
class EnvelopeSerializer(serializers.Serializer):
code = serializers.IntegerField(help_text="状态码,0表示成功")
data = serializer_class(many=many)
message = serializers.CharField(help_text="响应消息")
result = serializers.BooleanField(help_text="操作结果")
return EnvelopeSerializer