Skip to content

Commit 918f226

Browse files
authored
docs: "APIデザイン ガイドライン"を追加 (#870)
#632 に続く形で、独立した"APIデザイン ガイドライン"を追加する。内容とし てはとりあえず"Rust 以外の言語の API"とし、newtype以外にも言及したものを 用意する。 Refs: #631, #632
1 parent 1222335 commit 918f226

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ Issue 側で取り組み始めたことを伝えるか、最初に Draft プル
139139

140140
### Rust 以外の言語の API に関する方針
141141

142-
VOICEVOX CORE の主要機能は Rust で実装されることを前提としており、他の言語のラッパーでのみの機能追加はしない方針としています。これは機能の一貫性を保つための方針です。
143-
各言語の特性に応じた追加実装(例えば、Python での `style_id`[`NewType`](https://docs.python.org/ja/3/library/typing.html#newtype) 化など)は許容されます。
142+
[APIデザイン ガイドライン](./docs/guide/dev/api-design.md)をご覧ください。
144143

145144
## コアライブラリのビルド
146145

docs/guide/dev/api-design.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# APIデザイン ガイドライン
2+
3+
## Rust 以外の言語の API
4+
5+
VOICEVOX CORE の主要機能は Rust で実装されることを前提としており、他の言語のラッパーでのみの機能追加はしない方針としています。これは機能の一貫性を保つための方針です。
6+
7+
ただし機能追加ではない範囲で、各言語の習慣に適合するような変更は積極的に行っていきます。例えば:
8+
9+
* [`AudioQuery`](https://voicevox.github.io/voicevox_core/apis/rust_api/voicevox_core/struct.AudioQuery.html)といったJSONで表現可能なデータ型は、Pythonなら[Pydantic](https://docs.pydantic.dev)、JavaScriptなら[Zod](https://zod.dev/)といったライブラリを使って表現すべきです。
10+
* Rust APIとやりとりする際はJSONを介して変換します。
11+
* [`StyleId`](https://voicevox.github.io/voicevox_core/apis/rust_api/voicevox_core/struct.StyleId.html)といった[newtype](https://rust-unofficial.github.io/patterns/patterns/behavioural/newtype.html)は、そのままnewtypeとして表現するべきです。
12+
* 例えばPythonなら[`typing.NewType`](https://docs.python.org/ja/3/library/typing.html#newtype)で表現します。
13+
* オプショナルな引数は、キーワード引数がある言語であればキーワード引数で、ビルダースタイルが一般的な言語であればビルダースタイルで表現すべきです。
14+
15+
<!-- TODO: `render`の引数について: https://github.com/VOICEVOX/voicevox_core/pull/870#discussion_r1835601477 -->

0 commit comments

Comments
 (0)