Closed
Description
Is it possible to map a marshmallow_dataclass to a flask Namespace model?
IPv4 = NewType(
"IPv4", str, validate=marshmallow.validate.Regexp(r"^([0-9]{1,3}\\.){3}[0-9]{1,3}$")
)
@dataclass(order=True)
class Project:
name: str = field(
metadata=dict(description="The name of the project", load_only=True)
)
path: str
title: str
ip: IPv4
created_date: datetime = datetime.now()
Schema: ClassVar[Type[Schema]] = Schema
I don't want to have to re-write these:
project = api.model('Project', fields(Project))
project = api.model('Project', {
'path': fields.String(required=True, description='The path to the project'),
'name': fields.String(required=True, description='The name of the project'),
'title': fields.String(required=True, description='The title of the project'),
'ip': fields.String(required=True, description='An ip address of the project (e.g 10.10.0.1)'),
})
Then I would want to do something like @api.marshal_list_with(Project)