Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple the serialization/deserialization from Marshmallow #446

Open
BEllis opened this issue Jun 21, 2023 · 2 comments
Open

Decouple the serialization/deserialization from Marshmallow #446

BEllis opened this issue Jun 21, 2023 · 2 comments
Assignees
Milestone

Comments

@BEllis
Copy link

BEllis commented Jun 21, 2023

It would be nice for the APIFlask wrapper to be modified to make it easier to replace Marshmallow with our own serializer/reserialize and schema generator.

I've managed to this with some patching but would be nice if it was a first-class concern.

I've managed to do this in my case by wrapping the APIBlueprint class with my CAttrsAPIBlueprint class that replaces the input and output attributes with the same logic but uses a cattrs converter to serialize and deserialize and jsonschema_extractor to extract out the JSON schema. So far, this is working well.

I'd imagine making this first-class wouldl be something along the lines of,

app = APIFlask(import_name=__name__, title="myapp", serializer=MarshmallowSerializer(), schema_generator=MarshmallowSchemaGenerator())

or

app = APIFlask(import_name=__name__, title="myapp", serializer=CAttrsSerializer(), schema_generator=AttrsSchemaGenerator())

and input and output decorators would allow "Any" as the schema type.

@myblueprint.input(MyAttrsClass)
@myblueprint.output(MyOtherAttrsClass)
def my_endpoint(my_input: MyAttrsClass):
...
return (...)

@greyli
Copy link
Member

greyli commented Jul 26, 2023

Thanks. I would love to have this in APIFlask. But I think it's not easy since the code is heavily coupled with marshmallow projects. Maybe we could implement this in 3.0.

@greyli greyli added this to the 3.0.0 milestone Jul 26, 2023
@greyli greyli pinned this issue Dec 21, 2023
@greyli greyli self-assigned this Apr 4, 2024
@codekitchen-bot

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants