factset / quart-openapi

Module for Quart to add Flask-RESTPlus like functionality
https://factset.github.io/quart-openapi/
Other
82 stars 22 forks source link

Decorator syntax breaks class inheritance #17

Closed devdupont closed 5 years ago

devdupont commented 5 years ago

Looking at this to replace flask-restful since that extension is not Quart compatible. I noticed that the class-based resource model is the same. However, the @app.route('/') decorator syntax breaks Resource objects that use inheritance to override get, put, post, etc. Basic example:

from quart_openapi import Pint, Resource

app = Pint(__name__, title='Sample App')

@app.route('/hello')
class Hello(Resource):
  async def get(self):
    return "hello"

@app.route('/goodbye')
class Goodbye(Hello):
  async def get(self):
    return "goodbye"

app.run()

localhost:5000/hello -> "hello" localhost:5000/goodbye -> "hello"

Flask-RESTful got around this by using api.add_resource(MyResource, route) instead of the decorator syntax. Since Pint overrides the Quart() init, this could be added to the Pint class as an option. I see ._add_resource in the Pint class, but it's doing something else.

zeroshade commented 5 years ago

Thanks for bringing this up! that's an interesting situation that i didn't realize I had caused with the previous change (I think older versions < 1.3.9 would likely support the inheritance situation, but i'm not positive). Anyway i was looking into this and it looks like I've got a fix for the problem. I've put up a PR (#18) which fixes it and adds a test case which is your example here, let me know what you think!

devdupont commented 5 years ago

I changed those two lines in my local copy and everything appears to work now. Won't merge any changes until the library is updated, but thanks for the fix.

zeroshade commented 5 years ago

@flyinactor91 version 1.3.10 has been deployed to pypi containing this fix.