Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize api docs #133

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
+ Added an internal api for datapoints to `db.py`. (#125)
+ The REST api is now viewable via a Swagger (or ReDoc!) web page! (#34)
+ Core API routes have been refactored to use Flask's Pluggable Views. (#128)
+ Sorted the Swagger API into logical blueprints by Schema/MethodView. (#133)


## 0.5.0 (2019-02-28)
Expand Down
2 changes: 2 additions & 0 deletions src/trendlines/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def create_app():
# Initialize flask-rest-api for OpenAPI (Swagger) documentation
routes.api_class.init_app(app)
routes.api_class.register_blueprint(routes.api)
routes.api_class.register_blueprint(routes.api_datapoint)
routes.api_class.register_blueprint(routes.api_metric)

# Create the database file and populate initial tables if needed.
orm.create_db(app.config['DATABASE'])
Expand Down
12 changes: 8 additions & 4 deletions src/trendlines/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
api_class = Api()
api = Blueprint("api", __name__,
description="All API.")
api_datapoint = Blueprint("DataPoints", __name__,
description="CRUD datapoint(s)")
api_metric = Blueprint("Metrics", __name__,
description="CRUD metric(s)")


# Make sure all pages show our version.
Expand Down Expand Up @@ -132,7 +136,7 @@ def get_data_as_json(metric_name):
return jsonify(data)


@api.route("/api/v1/datapoint")
@api_datapoint.route("/api/v1/datapoint")
class DataPoint(MethodView):
def get(self):
"""
Expand All @@ -150,7 +154,7 @@ def post(self):
pass


@api.route("/api/v1/datapoint/<datapoint_id>")
@api_datapoint.route("/api/v1/datapoint/<datapoint_id>")
class DataPointById(MethodView):
def get(self, datapoint_id):
"""
Expand Down Expand Up @@ -185,7 +189,7 @@ def delete(self, datapoint_id):
return "", 204


@api.route("/api/v1/metric")
@api_metric.route("/api/v1/metric")
class Metric(MethodView):
def get(self):
"""
Expand Down Expand Up @@ -256,7 +260,7 @@ def post(self):
return jsonify(body), 201


@api.route("/api/v1/metric/<metric_name>")
@api_metric.route("/api/v1/metric/<metric_name>")
class MetricById(MethodView):
def get(self, metric_name):
"""
Expand Down