Skip to content

Commit

Permalink
🐛 修复启用调试时没有打印 API 文档链接的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
A-kirami committed Sep 6, 2023
1 parent 5f5dac1 commit 16b47c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions kirami/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,12 @@ def print_environment(self) -> None:


def _mixin_config(config: dict[str, Any]) -> dict[str, Any]:
config["fastapi_openapi_url"] = (
config.get("fastapi_openapi_url") if config["debug"] else None
)
if config["debug"]:
config |= {
"fastapi_openapi_url": config.get("fastapi_openapi_url", "/openapi.json"),
"fastapi_docs_url": config.get("fastapi_docs_url", "/docs"),
"fastapi_redoc_url": config.get("fastapi_redoc_url", "/redoc"),
}
config["fastapi_extra"] = {
"title": __metadata__.name,
"version": __metadata__.version,
Expand Down
5 changes: 3 additions & 2 deletions kirami/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def init(cls) -> None:

cls._routers.clear()

if getattr(bot_config, "fastapi_docs_url", None):
if bot_config.debug:
config = nonebot.get_driver().config
logger.debug(
f"API Docs Url is http://{bot_config.host}:{bot_config.port}{bot_config.fastapi_docs_url}"
f"API Docs Url is {BASE_URL.with_path(config.fastapi_docs_url)}"
)

@classmethod
Expand Down

0 comments on commit 16b47c4

Please sign in to comment.