restapi.models.schema.PartialSchema.from_dict
- classmethod PartialSchema.from_dict(fields, *, name='GeneratedSchema')
Generate a Schema class given a dictionary of fields.
from marshmallow import Schema, fields PersonSchema = Schema.from_dict({"name": fields.Str()}) print(PersonSchema().load({"name": "David"})) # => {'name': 'David'}
Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.
- Parameters:
fields (dict) – Dictionary mapping field names to field instances.
name (str) – Optional name for the class, which will appear in the
reprfor the class.
- Return type:
type
Added in version 3.0.0.
- Parameters:
fields (
dict[str,Union[Field,type]])name (
str, default:'GeneratedSchema')
- Return type:
type