Skip to content

FIX: manage_libraryfalseのときOpenAPIスキーマーの参照がエラーになる問題を修正 #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions voicevox_engine/app/openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
from pydantic import BaseModel

from voicevox_engine.model import BaseLibraryInfo, VvlibManifest
from voicevox_engine.model import BaseLibraryInfo, LibrarySpeaker, VvlibManifest


def configure_openapi_schema(app: FastAPI) -> FastAPI:
Expand All @@ -27,16 +28,18 @@ def custom_openapi() -> Any:
contact=app.contact,
license_info=app.license_info,
)
openapi_schema["components"]["schemas"][
"VvlibManifest"
] = VvlibManifest.schema()
# ref_templateを指定しない場合、definitionsを参照してしまうので、手動で指定する
base_library_info = BaseLibraryInfo.schema(
ref_template="#/components/schemas/{model}"
)
# definitionsは既存のモデルを重複して定義するため、不要なので削除
del base_library_info["definitions"]
openapi_schema["components"]["schemas"]["BaseLibraryInfo"] = base_library_info
additional_models: list[type[BaseModel]] = [
BaseLibraryInfo,
LibrarySpeaker,
VvlibManifest,
]
for model in additional_models:
# ref_templateを指定しない場合、definitionsを参照してしまうので、手動で指定する
schema = model.schema(ref_template="#/components/schemas/{model}")
# definitionsは既存のモデルを重複して定義するため、不要なので削除
if "definitions" in schema:
del schema["definitions"]
openapi_schema["components"]["schemas"][schema["title"]] = schema
app.openapi_schema = openapi_schema
return openapi_schema

Expand Down