-
Notifications
You must be signed in to change notification settings - Fork 314
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
base: main
Are you sure you want to change the base?
feat: 実行時にレスポンスの型チェックを行うように #2619
Conversation
🚀 プレビュー用ページを作成しました 🚀 更新時点でのコミットハッシュ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
まだWIPかもですが、提案がいくつか・・・!
src/store/proxy.ts
Outdated
import { EngineInfo } from "@/type/preload"; | ||
import Ajv, { ValidateFunction } from "ajv"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ちなみにzodでできたりしないですかね?
(依存を減らしたい)
There was a problem hiding this comment.
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も走らせたい気持ちがある)
There was a problem hiding this comment.
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のことですかね?それとも自作とか?
(自作だと流石に避けたい)
うーーーーん メンテが結構大変かもな気がしてきました。
ちょっと別のとこでコメントします!
There was a problem hiding this comment.
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とかが走るイメージ。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あーなるほどです!!
それは結構嬉しそう感。
src/store/proxy.ts
Outdated
} | ||
|
||
/** OpenAPIのレスポンスを検証する */ | ||
function createValidateOpenApiResponse() { |
There was a problem hiding this comment.
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/
以下のファイルに移動するのはどうでしょう?
src/store/proxy.ts
Outdated
/** | ||
* 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 ( |
There was a problem hiding this comment.
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
のとこだけのバリデータなのでは、という気もしてきました。。。
ちょっと結論出てないのですが、とりあえず相談まで 🙇
念のためのメモ |
内容
タイトル通りです。
関連 Issue
スクリーンショット・動画など
(なし)
その他
(なし)