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
I have added support for application/bson in my flask application, alongside application/json
This format is almost like json, with support for binary data, aside from text.
I want to use the same built-in validation as for application/json that flask-openapi3 supports, the only way I was able to find to make it work is by doing this:
fromflask_openapi3importrequestasflask_openapi3_requestdef_validate_body(body: type[BaseModel], func_kwargs: dict):
obj=Noneifrequest.is_json:
obj=request.get_json(silent=True)
elifrequest.is_bson:
obj=request.bsonifisinstance(obj, str):
body_model=body.model_validate_json(json_data=obj)
else:
body_model=body.model_validate(obj=obj)
func_kwargs["body"] =body_model# Patching body validation as only json is supported by defaultflask_openapi3_request._validate_body=_validate_body
Is there a more elegant, future proof way instead of patching the private api ?
Also, thank you for the great implementation you have in this project.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have added support for
application/bson
in my flask application, alongsideapplication/json
This format is almost like json, with support for binary data, aside from text.
A simple support in flask is to do this:
I want to use the same built-in validation as for
application/json
that flask-openapi3 supports, the only way I was able to find to make it work is by doing this:Is there a more elegant, future proof way instead of patching the private api ?
Also, thank you for the great implementation you have in this project.
Beta Was this translation helpful? Give feedback.
All reactions