getsling / flask-swagger

A swagger 2.0 spec extractor for flask
MIT License
457 stars 91 forks source link

Don't assume method verbs are View functions #38

Closed jamesboehmer closed 7 years ago

jamesboehmer commented 7 years ago

When iterating through the app's endpoints, we're assuming the View instance has methods named get, post, etc for each verb in in View's methods = ['GET', 'POST'] attribute. However this is not a requirement for implementations of flask.views.View.

For example, if I added a url rule with:

app.add_url_rule('/someview', view_func=SomeView.as_view('some_view', **kwargs))

the SomeView class is obligated to have a declaration of methods = [...], but not functions named get, post, put, delete, or anything which appears in the list. Flask swagger is assuming those functions exist in the view, and crashes on startup when it tries to access them. This changes checks for their existence before accessing them.

atlithorn commented 7 years ago

Nicely done!