Skip to content
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

追加: engine_manifest.json をバリデーション #1295

Merged
merged 3 commits into from
May 25, 2024

Conversation

tarepan
Copy link
Contributor

@tarepan tarepan commented May 21, 2024

内容

概要: engine_manifest.json のバリデーションを追加

現在の VOICEVOX ENGINE において、エンジンマニフェストである engine_manifest.json はバリデーション無しで JSON として読み込まれ、属性アクセスされている。これは危険である。
また JSON dict へ直接アクセスしているためマニフェストのスキーマが VOICEVOX ENGINE 内で必要とされず、結果としてスキーマが明示的に定義されていない。
これは pydantic が得意とする領域であり、スキーマをクラスで実装し JSON 読み込みを pydantic でおこなえば自動バリデーションがおこなわれる。

このような背景から、engine_manifest.json の pydantic 読み込みによるバリデーション追加を提案します。

関連 Issue

part of #1249

@tarepan tarepan requested a review from a team as a code owner May 21, 2024 18:29
@tarepan tarepan requested review from Hiroshiba and removed request for a team May 21, 2024 18:29
Copy link
Member

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

それぞれの値の意味とかも書けそうですね!!!

@@ -78,7 +121,7 @@ def load_manifest(manifest_path: Path) -> EngineManifest:
"""エンジンマニフェストを指定ファイルから読み込む。"""

root_dir = manifest_path.parent
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
manifest = EngineManifestJson.parse_file(manifest_path).dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もしかしたらutf8読み込めなくなってるとかはあるかも…?
(parse fileの仕様によりそう)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどです。
最低限、今の ENGINE のマニフェストファイルは読めています。
ファイルの文字列エンコーディング周りはところどころ実装が違う(encoding 指定しなかったり指定したり)ので、他の箇所含め注視していきます。

@Hiroshiba Hiroshiba merged commit 2f22130 into VOICEVOX:master May 25, 2024
4 checks passed
@tarepan tarepan deleted the refactor/manifest_json branch May 25, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants