"$schema" を設定ファイルのフィールドとして持ち、JSON Schema を効かせるパターン
整理
VS Code では JSON Schema を利用したエディタ支援に対応している
設定方法はいくつかあるが、そのうちの一つが設定ファイル自身に "$schema"というフィールドを持つパターン
値は string で、 JSON Schema ファイルの URI を表す(ローカルパスだったり https: 始まりだったりする)
これはJSON Schema の機能ではなく、VS Code の機能
Note that this syntax is VS Code-specific and not part of the JSON Schema specification. Adding the $schema key changes the JSON itself, which systems consuming the JSON might not expect, for example, schema validation might fail. If this is the case, you can use one of the other mapping methods.
ツール側は必ずしもこのフィールドを読まない
ツールはこれを許容するようスキーマを定義すればよい
あとは JSON Schema をホストしておけば、ユーザへ入力支援を勝手に与えられるという仕組み
"$schema" を利用できるツールをいくつか挙げてみる
TypeScript (tsconfig.json)
Deno (deno.{json,jsonc})
Prettier (prettierrc.json)
Turborepo (turbo.json)
どこの Schema を使うか
だいたい以下の3種類
1. 自分でホストしておくパターン
3. ライブラリに JSON Schema を含めておき、node_modules 内を参照するパターン