1、示例代码:
class TestDto(Schema):
swag_in = "body"
NAME = fields.String(type=["string", "null"], allow_none=True, description='名称', example='Test')
BEGIN_DATE = fields.DateTime(type=["string", "null"], allow_none=True, description='开始日期', required=False,
example='2022-10-30 00:00:00')
END_DATE = fields.DateTime(type=["string", "null"], allow_none=True, description='结束日期', required=False
, example='2023-10-30 00:00:00')
2、type=["string", "null"],jsonschema验证类型时允许为空
allow_none=True,marshmallow验证时允许为空
这段代码展示了如何在Python中定义一个`TestDto`类,继承自`Schema`,包含`NAME`、`BEGIN_DATE`和`END_DATE`字段。这些字段允许类型为字符串或null,且在验证时允许为空。示例中使用了`fields.String`和`fields.DateTime`来定义字段,并提供了描述和示例值。
4156

被折叠的 条评论
为什么被折叠?



