-
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
You can install Flask-OpenAPI from pip using:
pip install Flask-OpenAPI3-UI
The following packages will be installed as requirements:
- Flask
- PyYAML
- jsonschema
- mistune
- six
Initialising the Extension is similar to other Flask extensions. You can either pass the app
parameter to the OpenAPI
object, or use the init_app
method.
Parameter Example:
from flask_openapi import OpenAPI
def main():
app = create_app()
OpenAPI(app=app)
init_app
Example:
from flask_openapi import OpenAPI
openapi = OpenAPI()
def main():
app = create_app()
openapi.init_app(app)
You register OpenAPI YML specs with views using the openapi_spec
decorator.
Example:
from flask import current_app, jsonify
from flask_openapi import openapi_spec
@current_app.route('/', methods=['GET'])
@openapi_spec('/path/to/spec.yml')
def example_view():
return jsonify('Hello World')
By setting the swagger_ui
configuration key to True
, you can enable a web-based User Interface for viewing your API specifications. This UI is based of off Swagger UI.
Once enabled, you can visit the API documentation by going to the /apidocs/
route of your application.
Flask-OpenAPI provides some configuration keys that can:
- Customise the web UI
- Change the OpenAPI version
- Add predefined Schemas and Responses
- Add Security Schemas
See the Configuration page for more information.