diff --git a/run.py b/run.py index 4a8afa27b..b8afa1544 100644 --- a/run.py +++ b/run.py @@ -28,16 +28,17 @@ from voicevox_engine import __version__ from voicevox_engine.cancellable_engine import CancellableEngine -from voicevox_engine.downloadable_library import LibraryManager from voicevox_engine.engine_manifest import EngineManifestLoader from voicevox_engine.engine_manifest.EngineManifest import EngineManifest from voicevox_engine.kana_parser import create_kana, parse_kana +from voicevox_engine.library_manager import LibraryManager from voicevox_engine.metas.MetasStore import MetasStore, construct_lookup from voicevox_engine.model import ( AccentPhrase, AudioQuery, - DownloadableLibrary, - InstalledLibrary, + BaseLibraryInfo, + DownloadableLibraryInfo, + InstalledLibraryInfo, MorphableTargetInfo, ParseKanaBadRequest, ParseKanaError, @@ -845,10 +846,10 @@ def speaker_info( @app.get( "/downloadable_libraries", - response_model=list[DownloadableLibrary], + response_model=list[DownloadableLibraryInfo], tags=["音声ライブラリ管理"], ) - def downloadable_libraries() -> list[DownloadableLibrary]: + def downloadable_libraries() -> list[DownloadableLibraryInfo]: """ ダウンロード可能な音声ライブラリの情報を返します。 @@ -862,10 +863,10 @@ def downloadable_libraries() -> list[DownloadableLibrary]: @app.get( "/installed_libraries", - response_model=dict[str, InstalledLibrary], + response_model=dict[str, InstalledLibraryInfo], tags=["音声ライブラリ管理"], ) - def installed_libraries() -> dict[str, InstalledLibrary]: + def installed_libraries() -> dict[str, InstalledLibraryInfo]: """ インストールした音声ライブラリの情報を返します。 @@ -1226,7 +1227,7 @@ def setting_post( }, ) - # VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する + # BaseLibraryInfo/VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する # ref: https://fastapi.tiangolo.com/advanced/extending-openapi/#modify-the-openapi-schema def custom_openapi(): if app.openapi_schema: @@ -1245,6 +1246,13 @@ def custom_openapi(): 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 app.openapi_schema = openapi_schema return openapi_schema diff --git a/test/test_downloadable_library.py b/test/test_library_manager.py similarity index 99% rename from test/test_downloadable_library.py rename to test/test_library_manager.py index f3f47efe2..9924a0703 100644 --- a/test/test_downloadable_library.py +++ b/test/test_library_manager.py @@ -10,7 +10,7 @@ from fastapi import HTTPException -from voicevox_engine.downloadable_library import LibraryManager +from voicevox_engine.library_manager import LibraryManager vvlib_manifest_name = "vvlib_manifest.json" diff --git a/voicevox_engine/downloadable_library.py b/voicevox_engine/library_manager.py similarity index 96% rename from voicevox_engine/downloadable_library.py rename to voicevox_engine/library_manager.py index 1e0932da2..9168a0a4b 100644 --- a/voicevox_engine/downloadable_library.py +++ b/voicevox_engine/library_manager.py @@ -11,7 +11,11 @@ from pydantic import ValidationError from semver.version import Version -from voicevox_engine.model import DownloadableLibrary, InstalledLibrary, VvlibManifest +from voicevox_engine.model import ( + DownloadableLibraryInfo, + InstalledLibraryInfo, + VvlibManifest, +) __all__ = ["LibraryManager"] @@ -76,9 +80,9 @@ def downloadable_libraries(self): ) for i in range(1, 4) ] - return list(map(DownloadableLibrary.parse_obj, libraries)) + return list(map(DownloadableLibraryInfo.parse_obj, libraries)) - def installed_libraries(self) -> Dict[str, InstalledLibrary]: + def installed_libraries(self) -> Dict[str, InstalledLibraryInfo]: library = {} for library_dir in self.library_root_dir.iterdir(): if library_dir.is_dir(): diff --git a/voicevox_engine/model.py b/voicevox_engine/model.py index f2d3524ee..a90fcc8ac 100644 --- a/voicevox_engine/model.py +++ b/voicevox_engine/model.py @@ -127,9 +127,9 @@ class LibrarySpeaker(BaseModel): speaker_info: SpeakerInfo = Field(title="話者の追加情報") -class DownloadableLibrary(BaseModel): +class BaseLibraryInfo(BaseModel): """ - ダウンロード可能な音声ライブラリの情報 + 音声ライブラリの情報 """ name: str = Field(title="音声ライブラリの名前") @@ -140,7 +140,16 @@ class DownloadableLibrary(BaseModel): speakers: List[LibrarySpeaker] = Field(title="音声ライブラリに含まれる話者のリスト") -class InstalledLibrary(DownloadableLibrary): +# 今後InstalledLibraryInfo同様に拡張する可能性を考え、モデルを分けている +class DownloadableLibraryInfo(BaseLibraryInfo): + """ + ダウンロード可能な音声ライブラリの情報 + """ + + pass + + +class InstalledLibraryInfo(BaseLibraryInfo): """ インストール済み音声ライブラリの情報 """