python,jsonschema, marshmallow, “None is not of type ‘string‘

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验证时允许为空

     


版权声明:本文为XinShun原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。