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.
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
"""
|
|
用户扩展属性 API Schema
|
|
"""
|
|
from marshmallow import Schema, fields, validate
|
|
|
|
|
|
class UserAttributeQuery(Schema):
|
|
"""查询用户扩展属性请求"""
|
|
|
|
group = fields.String(
|
|
required=False, metadata={"description": "属性分组(可选,不传则返回所有分组)"}
|
|
)
|
|
|
|
|
|
class UserAttributeSetRequest(Schema):
|
|
"""设置用户扩展属性请求"""
|
|
|
|
attributes = fields.Dict(
|
|
required=True,
|
|
metadata={
|
|
"description": "属性字典,格式:{'key1': 'value1', 'key2': 'value2'} 或 {'group1': {'key1': 'value1'}, 'group2': {...}}"
|
|
},
|
|
)
|
|
group = fields.String(
|
|
required=False,
|
|
metadata={"description": "属性分组(可选,指定后 attributes 为简单键值对)"},
|
|
)
|
|
|
|
|
|
class UserAttributeItemRequest(Schema):
|
|
"""单个属性设置请求"""
|
|
|
|
attr_value = fields.String(required=True, metadata={"description": "属性值"})
|
|
attr_type = fields.String(
|
|
required=False,
|
|
load_default="string",
|
|
validate=validate.OneOf(["string", "int", "float", "bool", "json", "encrypted"]),
|
|
metadata={"description": "属性类型"},
|
|
)
|
|
|
|
|
|
class UserAttributeBatchRequest(Schema):
|
|
"""批量设置属性请求(支持类型)"""
|
|
|
|
class AttributeItem(Schema):
|
|
attr_group = fields.String(required=True, metadata={"description": "属性分组"})
|
|
attr_key = fields.String(required=True, metadata={"description": "属性键"})
|
|
attr_value = fields.String(required=True, metadata={"description": "属性值"})
|
|
attr_type = fields.String(
|
|
required=False,
|
|
load_default="string",
|
|
validate=validate.OneOf(
|
|
["string", "int", "float", "bool", "json", "encrypted"]
|
|
),
|
|
metadata={"description": "属性类型"},
|
|
)
|
|
description = fields.String(
|
|
required=False, metadata={"description": "属性描述"}
|
|
)
|
|
sort = fields.Integer(required=False, load_default=0, metadata={"description": "排序"})
|
|
|
|
attributes = fields.List(
|
|
fields.Nested(AttributeItem),
|
|
required=True,
|
|
metadata={"description": "属性列表"},
|
|
)
|
|
|