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
{{ message }}
Repository navigation
Any examples for Flask-RestPlus Resource constructors ? #40
Hi, I'm completely new to python world so excuse my lack of knowledge.
I read in the documentation that this also supports Flask-RestPlus Resource constructors, even though I could find neither here or on the internet any decent example that uses Flask-RestPlus with this library.
I tried my self and what I reached is that I need to consider the API resource like any other class and configure it with the binder, is this the correct way to do it?, because in the examples (while using with bare Flask) there was no need to configure the routes, as they are already a function, not a class, I don't know if this is the reason.
Strange thing, when the resource's constructor is written like this: def __init__(self, some_input: type_of_input, **kwargs):
It works, but if I removed the **kwargs it will not, I think Flask-Injector is passing the api variable through kwargs for some reason.
Even if I didn't call the super().__init__(*args, **kwargs) it still works.
What's the reason that I have to add kwargs when using the injector but not when I don't use it?
dependency_injector needs that constructor for calling itself, I've been diving into the documentation and no one mentions that this is a thing to consider, maybe should be included.
Activity
jstasiak commentedon Sep 5, 2019
There's an example piece of code in the test suite, I hope this helps.
AbdoDabbas commentedon Sep 6, 2019
Actually this example is ver simplified, and I'm trying the same but for some reason, it's failing, here's a question I posted on Stackoverflow if you can have a look at:
https://stackoverflow.com/questions/57806445/using-flask-injector-with-flask-restplus-causes-an-error-when-calling-the-api-re
AbdoDabbas commentedon Sep 6, 2019
Strange thing, when the resource's constructor is written like this:
def __init__(self, some_input: type_of_input, **kwargs):It works, but if I removed the
**kwargsit will not, I think Flask-Injector is passing theapivariable throughkwargsfor some reason.Even if I didn't call the
super().__init__(*args, **kwargs)it still works.What's the reason that I have to add
kwargswhen using the injector but not when I don't use it?jstasiak commentedon Sep 6, 2019
This is the signature of Flask-RESTPlus's
Resourceconstructor:(source)
The
apiparameter is required in order forResourceto operate correctly. flask-injector hardcodes this knowledge and passes api behind the scenes.If you want you can simplify your constructor to
But that's as far as the simplifications will go right now.
MariposaGentil commentedon Dec 15, 2020
dependency_injector needs that constructor for calling itself, I've been diving into the documentation and no one mentions that this is a thing to consider, maybe should be included.