Skip to content

Commit

Permalink
Allow Users to disable SwaggerUI via configuration (#28354)
Browse files Browse the repository at this point in the history
Due to potential issues, we want to give teams the opportunity to 
disable the swaggerUI. This can now be done via the configuration 
key: webserver.enable_swagger_ui. For backwards compatibility, 
this has been set to true by default, but for teams willing to disable 
this it can be set to false.
  • Loading branch information
gschuurman authored Dec 20, 2022
1 parent 6e3cee1 commit 032a542
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,13 @@
type: string
example: "dagrun_cleared,failed"
default: ~
- name: enable_swagger_ui
description: |
Boolean for running SwaggerUI in the webserver.
version_added: 2.6.0
type: boolean
example: ~
default: "True"
- name: run_internal_api
description: |
Boolean for running Internal API in the webserver.
Expand Down
3 changes: 3 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ audit_view_excluded_events = gantt,landing_times,tries,duration,calendar,graph,g
# Example: audit_view_included_events = dagrun_cleared,failed
# audit_view_included_events =

# Boolean for running SwaggerUI in the webserver.
enable_swagger_ui = True

# Boolean for running Internal API in the webserver.
run_internal_api = False

Expand Down
15 changes: 9 additions & 6 deletions airflow/www/extensions/init_appbuilder_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations

from airflow.configuration import conf
from airflow.utils.docs import get_docs_url


Expand All @@ -36,12 +37,14 @@ def init_appbuilder_links(app):
appbuilder.add_link(
name="Documentation", label="GitHub Repo", href="https://github.com/apache/airflow", category="Docs"
)
appbuilder.add_link(
name="Documentation",
label="REST API Reference (Swagger UI)",
href="/api/v1./api/v1_swagger_ui_index",
category="Docs",
)

if conf.getboolean("webserver", "enable_swagger_ui", fallback=True):
appbuilder.add_link(
name="Documentation",
label="REST API Reference (Swagger UI)",
href="/api/v1./api/v1_swagger_ui_index",
category="Docs",
)
appbuilder.add_link(
name="Documentation", label="REST API Reference (Redoc)", href="RedocView.redoc", category="Docs"
)
6 changes: 4 additions & 2 deletions airflow/www/extensions/init_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def _handle_method_not_allowed(ex):
return views.method_not_allowed(ex)

spec_dir = path.join(ROOT_APP_DIR, "api_connexion", "openapi")
connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True)
options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)}
connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options)
connexion_app.app = app
api_bp = connexion_app.add_api(
specification="v1.yaml", base_path=base_path, validate_responses=True, strict_validation=True
Expand All @@ -227,7 +228,8 @@ def init_api_internal(app: Flask) -> None:
base_path = "/internal_api/v1"

spec_dir = path.join(ROOT_APP_DIR, "api_internal", "openapi")
internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True)
options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)}
internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options)
internal_app.app = app
api_bp = internal_app.add_api(
specification="internal_api_v1.yaml",
Expand Down

0 comments on commit 032a542

Please sign in to comment.