Skip to content

Commit

Permalink
追加: GET / API にポータルページを配置 (#1169)
Browse files Browse the repository at this point in the history
* add: ルート API にポータルページを追加

* fix: lint

* fix: API タグを追加

* fix: エンジン名をマニフェストから自動で取得

* fix: ポータルからライセンス情報リンクを削除

* fix: スナップショット更新

* READMEと合わせる

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
tarepan and Hiroshiba authored May 5, 2024
1 parent 44aed37 commit 7ca6756
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates

from voicevox_engine import __version__
Expand Down Expand Up @@ -162,6 +163,25 @@ def get_core(core_version: Optional[str]) -> CoreAdapter:
)
)

@app.get("/", response_class=HTMLResponse, tags=["その他"])
async def get_portal() -> str:
"""ポータルページを返します。"""
engine_name = engine_manifest_data.name

return f"""
<html>
<head>
<title>{engine_name}</title>
</head>
<body>
<h1>{engine_name}</h1>
{engine_name} へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント</a></li>
</ul></body></html>
"""

app = configure_openapi_schema(app)

return app
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions test/e2e/single_api/__snapshots__/test_get_root.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# serializer version: 1
# name: test_get_root_200
'''

<html>
<head>
<title>DUMMY Engine</title>
</head>
<body>
<h1>DUMMY Engine</h1>
DUMMY Engine へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント</a></li>
</ul></body></html>

'''
# ---
12 changes: 12 additions & 0 deletions test/e2e/single_api/test_get_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
/ API のテスト
"""

from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


def test_get_root_200(client: TestClient, snapshot: SnapshotAssertion) -> None:
response = client.get("/")
assert response.status_code == 200
assert snapshot == response.content.decode("utf-8")

0 comments on commit 7ca6756

Please sign in to comment.