Skip to content

Commit

Permalink
__init__.py files cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Feb 16, 2018
1 parent c513d97 commit 3789538
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 13 additions & 9 deletions flask_rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
__version__ = '0.1.0'


class Api(object):
class Api:
"""Main class
def __init__(self, app=None):
Provides helpers to build a REST API using Flask.
self._apispec = ApiSpec()
:param Flask app: Flask application
"""

def __init__(self, app=None):
self._apispec = ApiSpec()
if app is not None:
self.init_app(app)

def init_app(self, app):
"""Initialize api"""
"""Initialize Api with application"""

self._app = app

Expand All @@ -42,21 +46,21 @@ def init_app(self, app):
for code in default_exceptions:
app.register_error_handler(code, handle_http_exception)

def register_blueprint(self, bp):
def register_blueprint(self, blp):
"""Register a blueprint in the application
Also registers documentation for the blueprint/resource
"""

self._app.register_blueprint(bp)
self._app.register_blueprint(blp)

# Register views in API documentation for this resource
bp.register_views_in_doc(self._app, self._apispec.spec)
blp.register_views_in_doc(self._app, self._apispec.spec)

# Add tag relative to this resource to the global tag list
self._apispec.spec.add_tag({
'name': bp.name,
'description': bp.description,
'name': blp.name,
'description': blp.description,
})

def definition(self, name):
Expand Down
9 changes: 6 additions & 3 deletions flask_rest_api/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ def make_apispec():
)


class ApiSpec(object):
class ApiSpec:
"""API specification class
def __init__(self, app=None):
:param Flask app: Flask application
"""

def __init__(self, app=None):
self.spec = make_apispec()
self.app = app

if app is not None:
self.init_app(app)

def init_app(self, app):
"""Initialize ApiSpec with application"""

self.app = app

Expand Down

0 comments on commit 3789538

Please sign in to comment.