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

feat: 実行時にレスポンスの型チェックを行うように #2619

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sevenc-nanashi
Copy link
Member

内容

タイトル通りです。

関連 Issue

スクリーンショット・動画など

(なし)

その他

(なし)

@sevenc-nanashi sevenc-nanashi requested a review from a team as a code owner March 17, 2025 14:42
@sevenc-nanashi sevenc-nanashi requested review from Hiroshiba and removed request for a team March 17, 2025 14:42
@voicevox-preview-pages
Copy link

voicevox-preview-pages bot commented Mar 17, 2025

🚀 プレビュー用ページを作成しました 🚀

更新時点でのコミットハッシュ:1b77b4a

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.

まだWIPかもですが、提案がいくつか・・・!

import { EngineInfo } from "@/type/preload";
import Ajv, { ValidateFunction } from "ajv";
Copy link
Member

Choose a reason for hiding this comment

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

ちなみにzodでできたりしないですかね?
(依存を減らしたい)

Copy link
Member Author

Choose a reason for hiding this comment

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

zodはjson schemaを扱えませんね。

方法としてはjson-schema-to-zodを走らせるツールをtools下に生やすのが現実的かも?(それを作るなら一緒にopenapi generatorも走らせたい気持ちがある)

Copy link
Member

Choose a reason for hiding this comment

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

あーそうか。。

それを作るなら一緒にopenapi generatorも走らせたい

これってpackage.jsonでインストールしてるgeneratorのことですかね?それとも自作とか?
(自作だと流石に避けたい)

うーーーーん メンテが結構大変かもな気がしてきました。
ちょっと別のとこでコメントします!

Copy link
Member Author

Choose a reason for hiding this comment

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

これってpackage.jsonでインストールしてるgeneratorのことですかね?それとも自作とか?

package.jsonのやつですね。イメージとしてはpnpm run tools:update-openapi http://localhost:50021をするとopenapi-generator-cliとかが走るイメージ。

Copy link
Member

Choose a reason for hiding this comment

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

あーなるほどです!!
それは結構嬉しそう感。

}

/** OpenAPIのレスポンスを検証する */
function createValidateOpenApiResponse() {
Copy link
Member

Choose a reason for hiding this comment

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

ちょっとこの量のコードをここに加えるのはメンテ性下がる気がするので(今更ですが。。。)、このファイルをsrc/store/proxy/index.tsに移して、この関数をsrc/store/proxy/以下のファイルに移動するのはどうでしょう?

Comment on lines 67 to 88
/**
* OpenAPIのスキーマを修正する。
*
* 具体的には以下の変更を行う:
* - `$ref`の参照先を`#/components/schemas/`から`openapi.json#/definitions/`に変更する
* - オブジェクトのプロパティ名をキャメルケースに変換する
*/
function patchOpenApiJson<T extends Record<string, unknown>>(schema: T): T {
return inner(cloneWithUnwrapProxy(schema)) as T;

function inner(schema: Record<string, unknown>): Record<string, unknown> {
if (schema["$ref"] != null) {
const ref = schema["$ref"];
if (typeof ref === "string") {
schema["$ref"] = ref.replace(
"#/components/schemas/",
"openapi.json#/definitions/",
);
}
}

if (
Copy link
Member

@Hiroshiba Hiroshiba Mar 17, 2025

Choose a reason for hiding this comment

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

こーーーーれちょっとメンテだいぶしんどい気がしますね・・・・・・・・・
openapiの何かが変わったときにこのあたりでエラー出ると、触れる人がかなり少ない気が。。。。。

補助ツールとかではなくエディタで、かつエンジン→エディタのメインストリームなのでもう少し硬いコードを書きたい気もします。
壊れたときに @sevenc-nanashi さんがかなり率先的に助けてくれる、とかならギリ行けるかも・・・・・・?

実は本当に必要なのはsupported featureのとこだけのバリデータなのでは、という気もしてきました。。。

ちょっと結論出てないのですが、とりあえず相談まで 🙇

@sabonerune
Copy link
Contributor

念のためのメモ
COEIROINK v1のようにやや古めなAPIに準拠したエンジンやAivisSpeechのようにAPIに拡張を加えたエンジンも動作することを確認する必要がある。

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.

APIの入出力のデータ構造をチェックする機能の追加
3 participants