Skip to content

Commit a780d6e

Browse files
authored
Add v2 API endpoint to fetch the openAPI spec (#2554)
* Add v2 API endpoint to fetch the openAPI spec - Supports EN and FR versions of the spec by passing in the lang query param * Split and rename endpoints * The endpoints are now `/v2/openapi-{en|fr}` instead of using a query string * The spec endpoint no longer requires auth * Make route paths consistent
1 parent e3e9db3 commit a780d6e

7 files changed

Lines changed: 505 additions & 1 deletion

File tree

app/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def register_blueprint(application):
286286

287287

288288
def register_v2_blueprints(application):
289-
from app.authentication.auth import requires_auth
289+
from app.authentication.auth import requires_auth, requires_no_auth
290+
from app.v2.api_spec.get_api_spec import v2_api_spec_blueprint
290291
from app.v2.inbound_sms.get_inbound_sms import (
291292
v2_inbound_sms_blueprint as get_inbound_sms,
292293
)
@@ -310,6 +311,8 @@ def register_v2_blueprints(application):
310311

311312
register_notify_blueprint(application, get_inbound_sms, requires_auth)
312313

314+
register_notify_blueprint(application, v2_api_spec_blueprint, requires_no_auth)
315+
313316

314317
def init_app(app):
315318
@app.before_request

app/v2/api_spec/__init__.py

Whitespace-only changes.

app/v2/api_spec/get_api_spec.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
from flask import Blueprint, current_app, send_file
4+
5+
v2_api_spec_blueprint = Blueprint("v2_api_spec", __name__, url_prefix="/v2")
6+
7+
8+
@v2_api_spec_blueprint.route("/openapi-en", methods=["GET"])
9+
def get_v2_api_spec_en():
10+
"""
11+
Returns the English OpenAPI specification for the v2 Notifications API.
12+
"""
13+
spec_path = os.path.join(current_app.root_path, "openapi/v2-notifications-api-en.yaml")
14+
spec_path = os.path.abspath(spec_path)
15+
16+
return send_file(spec_path, mimetype="application/yaml", as_attachment=False, download_name="v2-notifications-api.yaml")
17+
18+
19+
@v2_api_spec_blueprint.route("/openapi-fr", methods=["GET"])
20+
def get_v2_api_spec_fr():
21+
"""
22+
Returns the French OpenAPI specification for the v2 Notifications API.
23+
"""
24+
spec_path = os.path.join(current_app.root_path, "openapi/v2-notifications-api-fr.yaml")
25+
spec_path = os.path.abspath(spec_path)
26+
27+
return send_file(spec_path, mimetype="application/yaml", as_attachment=False, download_name="v2-notifications-api.yaml")

0 commit comments

Comments
 (0)