Skip to content
Snippets Groups Projects
Commit df9908ae authored by Remco Tukker's avatar Remco Tukker
Browse files

more convenient documentation of the api by using the sphinxcontrib.autohttp package

parent ef118877
Branches
Tags
1 merge request!12Feature/comp 114 python code quality
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
...@@ -17,6 +17,22 @@ def migrate_database(config: dict) -> None: ...@@ -17,6 +17,22 @@ def migrate_database(config: dict) -> None:
migration_utils.upgrade(dsn) migration_utils.upgrade(dsn)
def _create_app(app_config) -> Flask:
# used by sphinx to create documentation without config and db migrations
app = Flask(__name__)
CORS(app)
app.config['CONFIG_PARAMS'] = app_config
from compendium_v2.routes import default
app.register_blueprint(default.routes, url_prefix='/')
from compendium_v2.routes import api
app.register_blueprint(api.routes, url_prefix='/api')
return app
def create_app() -> Flask: def create_app() -> Flask:
""" """
overrides default settings with those found overrides default settings with those found
...@@ -30,16 +46,7 @@ def create_app() -> Flask: ...@@ -30,16 +46,7 @@ def create_app() -> Flask:
with open(os.environ['SETTINGS_FILENAME']) as f: with open(os.environ['SETTINGS_FILENAME']) as f:
app_config = config.load(f) app_config = config.load(f)
app = Flask(__name__) app = _create_app(app_config)
CORS(app)
app.config['CONFIG_PARAMS'] = app_config
from compendium_v2.routes import default
app.register_blueprint(default.routes, url_prefix='/')
from compendium_v2.routes import api
app.register_blueprint(api.routes, url_prefix='/api')
logging.info('Flask app initialized') logging.info('Flask app initialized')
......
"""
API Endpoints
=========================
.. contents:: :local:
/api/
---------------------
"""
import logging import logging
from flask import Blueprint from flask import Blueprint
......
"""
Default Endpoints
=========================
.. contents:: :local:
/version
---------------------
.. autofunction:: compendium_v2.routes.default.version
"""
import pkg_resources import pkg_resources
from flask import Blueprint, jsonify, render_template, Response from flask import Blueprint, jsonify, render_template, Response
......
...@@ -9,14 +9,8 @@ Responses to valid requests are returned as JSON messages. ...@@ -9,14 +9,8 @@ Responses to valid requests are returned as JSON messages.
The server will therefore return an error unless The server will therefore return an error unless
`application/json` is in the `Accept` request header field. `application/json` is in the `Accept` request header field.
HTTP communication and JSON grammar details are .. qrefflask:: compendium_v2:_create_app(None)
beyond the scope of this document. :autoquickref:
Please refer to [RFC 2616](https://tools.ietf.org/html/rfc2616)
and www.json.org for more details.
.. contents:: :local:
.. automodule:: compendium_v2.routes.default
.. automodule:: compendium_v2.routes.api
.. autoflask:: compendium_v2:_create_app(None)
:undoc-static:
...@@ -73,7 +73,9 @@ release = '0.0' ...@@ -73,7 +73,9 @@ release = '0.0'
extensions = [ extensions = [
'sphinx_rtd_theme', 'sphinx_rtd_theme',
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.coverage' 'sphinx.ext.coverage',
'sphinxcontrib.autohttp.flask',
'sphinxcontrib.autohttp.flaskqref'
] ]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
......
...@@ -11,4 +11,3 @@ Publishers ...@@ -11,4 +11,3 @@ Publishers
.. automodule:: compendium_v2.publishers.survey_publisher_2022 .. automodule:: compendium_v2.publishers.survey_publisher_2022
:members: :members:
...@@ -13,6 +13,7 @@ python-dotenv ...@@ -13,6 +13,7 @@ python-dotenv
sphinx sphinx
sphinx-rtd-theme sphinx-rtd-theme
sphinxcontrib-httpdomain
tox tox
mypy mypy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment