Return codes do not work with flask-restful
- Dominant language
- Python
- Stars
- 652
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
Hi :-),
*At first, let me thank you for this project. It makes documenting my API much easier.*
I'm trying to use the `@marhal_with` with a return code (using `flask-restful` `Resource`), however, I get a `TypeError: Object of type 'Response' is not JSON serializable`.
```python
class User(Resource):
@use_kwargs(UserSchema())
@marshal_with(UserSchema, code=200)
def get(self, id: int, **kwargs):
user = session.query(User).filter_by(id=id).first()
return user, 200
```
If I leave the return without the status (i.e. `return user`) everything works as expected.
Using debugger, I found that (in `wrapper.Wrapper.marshal_result`)
* when there is **no status code** in return, `flask-apispec` returns `flask.Response` with status 200,
* and when there is **some status code** a tuple `(Response[200], status_code)` is returned.
Then flask restful tries to jsonify the `Response`, which causes the `TypeError`.
Am I doing something wrong? Or is that an incompatibility between `flask-apispec` and `flask-restful`?
Thanks for response.
Krystof
P.S. the purpose is not to return code 200 from user retrieve but 201 when creating a user, however, the code example is much simpler for user retrieve.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.