给棉花糖加点糖。
marshmallow-jam的Python项目详细描述
再来点棉花糖。
示例
使用批注进行架构描述。
fromjamimportSchemaclassBar(Schema):baz:strclassFoo(Schema):bar:Barfoo:Foo=Foo().load({"bar":{"baz":"quux"}})assertfoo.bar.baz=="quux"
当注释不够时
classFoo(Schema):bar:str=fields.Email()
映射规则
基本类型
annotation | marshmallow field |
---|---|
^{tt1}$ | ^{tt2}$ |
^{tt3}$ | ^{tt4}$ |
^{tt5}$ | ^{tt6}$ |
^{tt7}$ | ^{tt8}$ |
^{tt9}$ | ^{tt10}$ |
^{tt11}$ | ^{tt12}$ |
^{tt13}$ | ^{tt14}$ |
^{tt15}$ | ^{tt16}$ |
^{tt17}$ | ^{tt18}$ |
^{tt19}$ | ^{tt20}$ |
所有字段都将required作为可选使用 typing.Optional[X]
许多
annotation | marshmallow field |
---|---|
^{tt23}$ | ^{tt24}$ |
^{tt25}$ | ^{tt26}$ |
嵌套
annotation | marshmallow field |
---|---|
^{tt27}$ | ^{tt28}$ |
^{tt29}$ | ^{tt28}$ |
^{tt31}$ | ^{tt32}$ |