Skip to content

Commit 1892ff0

Browse files
hideyukiMORIhideyukiMORIclaude
authored
docs: ドキュメント全体の監査・多角的修正(3ラウンド) (#104)
Round 1 — 致命的な誤りと古いコマンド: - configure-auth.md (EN/JA): BEARER_TOKENS/API_KEYS をJSON配列形式に修正 (カンマ区切りはJSONDecodeErrorになる) - ja/reference/configuration.md: .env例のCORS_ORIGINS/BEARER_TOKENSをJSON配列形式に修正 - design-philosophy.md (EN/JA): 削除済みの `uv run export-openapi` を `uv run python src/scripts/export_openapi.py` に修正 - 全言語のテスト数を167+に統一(EN:165+, JA/DE/FR/ZH/PT-BR:135+ がすべて古かった) - sqlalchemy-repository.md (EN): セクション番号の飛び(4→6)を修正(→5)、末尾の孤立```を削除 - todo/current.md: v0.2.0作業中のTODOリスト(全タスク未完のまま放置)をv1.x完了後の状態に更新 Round 2 — 抜けと不整合: - new-project.md (EN): BearerTokenMiddleware/ApiKeyAuthMiddleware/CORSMiddlewareのimport文を追加 - configure-auth.md (EN/JA): TokenIssuerProtocol セクションをEN版に追加しJA版と整合 - configure-auth.md (EN/JA): importパスを nene2.auth トップレベルに統一 - architecture.md (EN/JA): schema.pyの説明に「新規プロジェクトはドメイン別ensure_schema」の注記追加 - ja/how-to/run-tests.md: テスト構造のサブディレクトリをEN版に合わせて列挙 - ja/how-to/sqlalchemy-repository.md: Section 5「transactional()を使った原子的マルチライト」を追加 (EN版には既に存在したがJA版に欠落していた) Round 3 — JA版の欠けているページ作成: - docs/ja/how-to/new-project.md: 新規作成(EN版 new-project.md の完全日本語翻訳) Co-authored-by: hideyukiMORI <info.xion.cc@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 31dc1ab commit 1892ff0

19 files changed

Lines changed: 339 additions & 122 deletions

docs/de/tutorials/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ curl http://localhost:8080/notes
4747
uv run pytest
4848
```
4949

50-
Mehr als 135 Tests sollten erfolgreich sein.
50+
Mehr als 167 Tests sollten erfolgreich sein.
5151

5252
## Nächste Schritte
5353

docs/explanation/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def create_note(body: CreateNoteBody) -> JSONResponse:
5555

5656
- SQLAlchemy Core (no ORM) with parameterised queries
5757
- Queries are executed via `SqlAlchemyQueryExecutor`
58-
- Table schema is managed centrally in `src/example/schema.py`
58+
- Table schema: the example app uses a central `src/example/schema.py`; for new projects, define `ensure_schema()` in each domain's `sqlalchemy_repository.py` and call each from `create_app()`
5959

6060
## Middleware stack
6161

docs/explanation/design-philosophy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nene2-python shares the same design philosophy as PHP NENE2.
66

77
### API First
88

9-
The JSON API contract and OpenAPI schema are defined before the database schema. Use `uv run export-openapi` to export a static `openapi.yaml` at any time.
9+
The JSON API contract and OpenAPI schema are defined before the database schema. Use `uv run python src/scripts/export_openapi.py` to export a static `openapi.yaml` at any time.
1010

1111
### Thin HTTP layer
1212

docs/fr/tutorials/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ curl http://localhost:8080/notes
4747
uv run pytest
4848
```
4949

50-
Plus de 135 tests doivent tous réussir.
50+
Plus de 167 tests doivent tous réussir.
5151

5252
## Étapes suivantes
5353

docs/how-to/configure-auth.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Add to your `.env` file:
1010

1111
```dotenv
1212
BEARER_TOKEN_ENABLED=true
13-
BEARER_TOKENS=token1,token2,token3
13+
BEARER_TOKENS=["token1","token2","token3"]
1414
```
1515

1616
### Behaviour
@@ -31,7 +31,7 @@ curl -H "Authorization: Bearer token1" http://localhost:8080/notes
3131

3232
```dotenv
3333
API_KEY_ENABLED=true
34-
API_KEYS=key1,key2
34+
API_KEYS=["key1","key2"]
3535
```
3636

3737
### Behaviour
@@ -64,8 +64,7 @@ client = TestClient(create_app(AppSettings(bearer_token_enabled=False)))
6464
Implement `TokenVerifierProtocol` and raise `TokenVerificationException` on failure.
6565

6666
```python
67-
from nene2.auth import TokenVerificationException
68-
from nene2.auth.interfaces import TokenVerifierProtocol
67+
from nene2.auth import TokenVerificationException, TokenVerifierProtocol
6968
import jwt
7069

7170
class JwtTokenVerifier:
@@ -81,3 +80,19 @@ class JwtTokenVerifier:
8180
```
8281

8382
Pass your verifier directly to `BearerTokenMiddleware`.
83+
84+
## Custom TokenIssuer (e.g. JWT)
85+
86+
Implement `TokenIssuerProtocol` to issue tokens (e.g. for a login endpoint).
87+
88+
```python
89+
from nene2.auth import TokenIssuerProtocol
90+
import jwt
91+
92+
class JwtTokenIssuer:
93+
def __init__(self, secret: str) -> None:
94+
self._secret = secret
95+
96+
def issue(self, claims: dict[str, object]) -> str:
97+
return jwt.encode(claims, self._secret, algorithm="HS256")
98+
```

docs/how-to/new-project.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Create `src/app.py`:
5555
from fastapi import FastAPI
5656
from fastapi.exceptions import RequestValidationError
5757

58+
from fastapi.middleware.cors import CORSMiddleware
59+
60+
from nene2.auth import ApiKeyAuthMiddleware, BearerTokenMiddleware, LocalTokenVerifier
5861
from nene2.config import AppSettings
5962
from nene2.log import setup_logging
6063
from nene2.middleware import ErrorHandlerMiddleware

docs/how-to/sqlalchemy-repository.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _make_repo() -> SqlAlchemyBookRepository:
232232

233233
---
234234

235-
## 6. Atomic multi-write operations with `transactional()`
235+
## 5. Atomic multi-write operations with `transactional()`
236236

237237
When a UseCase needs to write to multiple tables atomically, use `SqlAlchemyTransactionManager.transactional()` together with `_in_tx` repository methods.
238238

@@ -344,4 +344,3 @@ class InMemoryTransactionManager(DatabaseTransactionManagerInterface):
344344
```
345345

346346
> **Rollback on exception**: `SqlAlchemyTransactionManager.transactional()` uses `engine.begin()` — any exception inside the callback triggers an automatic rollback. Domain exceptions (`AccountNotFoundException`, etc.) propagate normally after rollback.
347-
```

docs/ja/explanation/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def create_note(body: CreateNoteBody) -> JSONResponse:
5454

5555
- SQLAlchemy Core(ORM なし)でパラメータ化クエリを実行
5656
- `SqlAlchemyQueryExecutor` でクエリを抽象化
57-
- テーブルスキーマは `src/example/schema.py` で一元管理
57+
- テーブルスキーマ: example アプリは `src/example/schema.py` で一元管理。新規プロジェクトでは各ドメインの `sqlalchemy_repository.py``ensure_schema()` を定義し `create_app()` から順番に呼ぶ
5858

5959
## ミドルウェアスタック
6060

docs/ja/explanation/design-philosophy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nene2-python は PHP 版 NENE2 と同一の設計思想を持ちます。
66

77
### API First
88

9-
JSON API と OpenAPI 契約を中心に据えます。DB 設計より先に API の形を定義し、スキーマを `uv run export-openapi` で生成します。
9+
JSON API と OpenAPI 契約を中心に据えます。DB 設計より先に API の形を定義し、スキーマを `uv run python src/scripts/export_openapi.py` で生成します。
1010

1111
### 薄い HTTP 層
1212

docs/ja/how-to/configure-auth.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ nene2-python は Bearer Token 認証と API Key 認証の 2 種類をサポー
1111

1212
```dotenv
1313
BEARER_TOKEN_ENABLED=true
14-
BEARER_TOKENS=token1,token2,token3
14+
BEARER_TOKENS=["token1","token2","token3"]
1515
```
1616

1717
### 動作
@@ -32,7 +32,7 @@ curl -H "Authorization: Bearer token1" http://localhost:8080/notes
3232

3333
```dotenv
3434
API_KEY_ENABLED=true
35-
API_KEYS=key1,key2
35+
API_KEYS=["key1","key2"]
3636
```
3737

3838
### 動作
@@ -66,8 +66,7 @@ client = TestClient(create_app(AppSettings(bearer_token_enabled=False)))
6666
`TokenVerifierProtocol` を実装することで、JWT や外部サービスによる検証を追加できます。
6767

6868
```python
69-
from nene2.auth.interfaces import TokenVerifierProtocol
70-
from nene2.auth.exceptions import TokenVerificationException
69+
from nene2.auth import TokenVerificationException, TokenVerifierProtocol
7170
import jwt
7271

7372
class JwtTokenVerifier:
@@ -89,7 +88,7 @@ class JwtTokenVerifier:
8988
`TokenIssuerProtocol` を実装して、JWT などのトークンを発行できます。
9089

9190
```python
92-
from nene2.auth.interfaces import TokenIssuerProtocol
91+
from nene2.auth import TokenIssuerProtocol
9392
import jwt
9493

9594
class JwtTokenIssuer:

0 commit comments

Comments
 (0)