Skip to content

Commit fd0096a

Browse files
authored
add Flask-RESTX API structure with OpenAPI documentation (#138)
1 parent f2397df commit fd0096a

File tree

5 files changed

+763
-6
lines changed

5 files changed

+763
-6
lines changed

app/poetry.lock

Lines changed: 74 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
name = "strelka-ui"
33
version = "2.43"
44
description = "Strelka's File Submission Portal"
5-
authors = [
6-
"Paul Hutelmyer <Paul.Hutelmyer@Target.com>",
7-
]
5+
authors = ["Paul Hutelmyer <Paul.Hutelmyer@Target.com>"]
86

97
[tool.poetry.dependencies]
108
flask = "^3.1.1"
119
flask-Cors = "^6.0.0"
1210
flask-migrate = "^4.0.7"
11+
flask-restx = "^1.3.0"
1312
flask-sqlalchemy = "3.0.5"
1413
grpcio = "^1.53.2"
1514
grpcio-tools = "^1.41.0"
@@ -21,7 +20,7 @@ psycopg2-binary = "^2.9.10"
2120
py7zr = "^0.22.0"
2221
python = "~3.10.14"
2322
python-dateutil = "^2.9.0-post.0"
24-
python-dotenv = "^1.0.1"
23+
python-dotenv = "^1.0.1"
2524
python-magic = "^0.4.27"
2625
rarfile = "^4.2"
2726
requests = "^2.32.4"

app/strelka_ui/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from strelka_ui.blueprints.strelka import strelka
1919
from strelka_ui.blueprints.ui import ui
2020
from strelka_ui.models import db
21+
from strelka_ui.api import api_blueprint
2122

2223

2324
def create_app() -> Flask:
@@ -55,6 +56,9 @@ def create_app() -> Flask:
5556
app.register_blueprint(auth, url_prefix="/api/auth")
5657
app.register_blueprint(strelka, url_prefix="/api/strelka")
5758

59+
# This provides Swagger UI at /api/docs
60+
app.register_blueprint(api_blueprint)
61+
5862
return app
5963

6064

app/strelka_ui/api/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Flask-RESTX API Configuration for Strelka UI
3+
4+
This module sets up the base API structure with namespaces and OpenAPI documentation.
5+
Auto-generates comprehensive API documentation for external clients.
6+
"""
7+
8+
from flask import Blueprint
9+
from flask_restx import Api
10+
11+
# Create API blueprint
12+
api_blueprint = Blueprint('api', __name__, url_prefix='/api')
13+
14+
# Configure Flask-RESTX API with comprehensive OpenAPI settings
15+
api = Api(
16+
api_blueprint,
17+
version='v1',
18+
title='Strelka UI API',
19+
description='''https://github.com/target/strelka-ui
20+
''',
21+
doc='/docs/', # Swagger UI endpoint
22+
contact='Strelka UI Team',
23+
license='Apache 2.0',
24+
license_url='https://www.apache.org/licenses/LICENSE-2.0.html',
25+
validate=True, # Enable request/response validation
26+
ordered=True, # Maintain endpoint order in documentation
27+
)
28+
29+
# Security schemes for OpenAPI documentation
30+
authorizations = {
31+
'apikey': {
32+
'type': 'apiKey',
33+
'in': 'header',
34+
'name': 'X-API-KEY',
35+
'description': 'API Key for authentication. Obtain via /auth/apikey endpoint.'
36+
}
37+
}
38+
39+
# Apply security schemes to API
40+
api.authorizations = authorizations
41+
42+
# Import resources to register Flask-RESTX documentation endpoints
43+
from strelka_ui.api import resources # pylint: disable=unused-import,import-outside-toplevel

0 commit comments

Comments
 (0)