Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
api: support to config disabling Swagger UI in api service (#24440)
Bowen Liang6e674b511ab0
diff --git a/api/.env.example b/api/.env.exampleindex 3052dbfe2bc..e947c5584b1 100644--- a/api/.env.example+++ b/api/.env.example@@ -564,3 +564,7 @@ QUEUE_MONITOR_THRESHOLD=200QUEUE_MONITOR_ALERT_EMAILS=# Monitor interval in minutes, default is 30 minutesQUEUE_MONITOR_INTERVAL=30++# Swagger UI configuration+SWAGGER_UI_ENABLED=true+SWAGGER_UI_PATH=/swagger-ui.htmldiff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.pyindex 2bccc4b7a02..7638cd18996 100644--- a/api/configs/feature/__init__.py+++ b/api/configs/feature/__init__.py@@ -1,4 +1,4 @@-from typing import Annotated, Literal, Optional+from typing import Literal, Optionalfrom pydantic import (AliasChoices,@@ -976,6 +976,18 @@ class WorkflowLogConfig(BaseSettings):)+class SwaggerUIConfig(BaseSettings):+ SWAGGER_UI_ENABLED: bool = Field(+ description="Whether to enable Swagger UI in api module",+ default=True,+ )++ SWAGGER_UI_PATH: str = Field(+ description="Swagger UI page path in api module",+ default="/swagger-ui.html",+ )++class FeatureConfig(# place the configs in alphabet orderAppExecutionConfig,@@ -1007,6 +1019,7 @@ class FeatureConfig(WorkspaceConfig,LoginConfig,AccountConfig,+ SwaggerUIConfig,# hosted services configHostedServiceConfig,CeleryBeatConfig,diff --git a/api/extensions/ext_login.py b/api/extensions/ext_login.pyindex 9e5c71fb1d2..cd01a310683 100644--- a/api/extensions/ext_login.py+++ b/api/extensions/ext_login.py@@ -21,7 +21,7 @@ login_manager = flask_login.LoginManager()def load_user_from_request(request_from_flask_login):"""Load user based on the request."""# Skip authentication for documentation endpoints- if request.path.endswith("/docs") or request.path.endswith("/swagger.json"):+ if dify_config.SWAGGER_UI_ENABLED and request.path.endswith((dify_config.SWAGGER_UI_PATH, "/swagger.json")):return Noneauth_header = request.headers.get("Authorization", "")diff --git a/api/libs/external_api.py b/api/libs/external_api.pyindex d5e3c76d20b..a630a97fd6a 100644--- a/api/libs/external_api.py+++ b/api/libs/external_api.py@@ -3,11 +3,12 @@ import sysfrom collections.abc import Mappingfrom typing import Any-from flask import current_app, got_request_exception+from flask import Blueprint, Flask, current_app, got_request_exceptionfrom flask_restx import Apifrom werkzeug.exceptions import HTTPExceptionfrom werkzeug.http import HTTP_STATUS_CODES+from configs import dify_configfrom core.errors.error import AppInvokeQuotaExceededError@@ -115,8 +116,13 @@ class ExternalApi(Api):}}- def __init__(self, *args, **kwargs):+ def __init__(self, app: Blueprint | Flask, *args, **kwargs):kwargs.setdefault("authorizations", self._authorizations)kwargs.setdefault("security", "Bearer")- super().__init__(*args, **kwargs)+ kwargs["add_specs"] = dify_config.SWAGGER_UI_ENABLED+ kwargs["doc"] = dify_config.SWAGGER_UI_PATH if dify_config.SWAGGER_UI_ENABLED else False++ # manual separate call on construction and init_app to ensure configs in kwargs effective+ super().__init__(app=None, *args, **kwargs) # type: ignore+ self.init_app(app, **kwargs)register_external_error_handlers(self)diff --git a/docker/.env.example b/docker/.env.exampleindex 711898016ec..c6ed2acb35e 100644--- a/docker/.env.example+++ b/docker/.env.example@@ -1250,6 +1250,10 @@ QUEUE_MONITOR_ALERT_EMAILS=# Monitor interval in minutes, default is 30 minutesQUEUE_MONITOR_INTERVAL=30+# Swagger UI configuration+SWAGGER_UI_ENABLED=true+SWAGGER_UI_PATH=/swagger-ui.html+# Celery schedule tasks configurationENABLE_CLEAN_EMBEDDING_CACHE_TASK=falseENABLE_CLEAN_UNUSED_DATASETS_TASK=falsediff --git a/docker/docker-compose.yaml b/docker/docker-compose.yamlindex d3b75d93afc..0b9de5fc43f 100644--- a/docker/docker-compose.yaml+++ b/docker/docker-compose.yaml@@ -566,6 +566,8 @@ x-shared-env: &shared-api-worker-envQUEUE_MONITOR_THRESHOLD: ${QUEUE_MONITOR_THRESHOLD:-200}QUEUE_MONITOR_ALERT_EMAILS: ${QUEUE_MONITOR_ALERT_EMAILS:-}QUEUE_MONITOR_INTERVAL: ${QUEUE_MONITOR_INTERVAL:-30}+ SWAGGER_UI_ENABLED: ${SWAGGER_UI_ENABLED:-true}+ SWAGGER_UI_PATH: ${SWAGGER_UI_PATH:-/swagger-ui.html}ENABLE_CLEAN_EMBEDDING_CACHE_TASK: ${ENABLE_CLEAN_EMBEDDING_CACHE_TASK:-false}ENABLE_CLEAN_UNUSED_DATASETS_TASK: ${ENABLE_CLEAN_UNUSED_DATASETS_TASK:-false}ENABLE_CREATE_TIDB_SERVERLESS_TASK: ${ENABLE_CREATE_TIDB_SERVERLESS_TASK:-false}