You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
Hello,
You are not mentioning it, but I guess what you call a flask namespace model is actually a flask-restplus model, right ?
Marshmallow-dataclass generates (as its name suggests) marshmallow schemas. So what you are looking for is actually a way to use marshmallow schemas with create flask_restplus. A quick google search for that gives me this result: https://github.com/joeyorlando/flask-restplus-marshmallow
Is it possible to map a marshmallow_dataclass to a flask Namespace model?
I don't want to have to re-write these:
Then I would want to do something like
@api.marshal_list_with(Project)
The text was updated successfully, but these errors were encountered: