Skip to content

Commit 82f8280

Browse files
committed
README flask integration updated
1 parent b5aabf2 commit 82f8280

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,46 @@ or simply specify response factory for shortcuts
181181
Flask
182182
*****
183183

184+
Decorator
185+
=========
186+
187+
Flask views can be integrated by `FlaskOpenAPIViewDecorator` decorator.
188+
189+
.. code-block:: python
190+
191+
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
192+
193+
openapi = FlaskOpenAPIViewDecorator.from_spec(spec)
194+
195+
@app.route('/home')
196+
@openapi
197+
def home():
198+
pass
199+
200+
If you want to decorate class based view you can use the decorators attribute:
201+
202+
.. code-block:: python
203+
204+
class MyView(View):
205+
decorators = [openapi]
206+
207+
View
208+
====
209+
210+
As an alternative to the decorator-based integration, Flask method based views can be integrated by inheritance from `FlaskOpenAPIView` class.
211+
212+
.. code-block:: python
213+
214+
from openapi_core.contrib.flask.views import FlaskOpenAPIView
215+
216+
class MyView(FlaskOpenAPIView):
217+
pass
218+
219+
app.add_url_rule('/home', view_func=MyView.as_view('home', spec))
220+
221+
Low level
222+
=========
223+
184224
You can use FlaskOpenAPIRequest a Flask/Werkzeug request factory:
185225

186226
.. code-block:: python

0 commit comments

Comments
 (0)