openapi-usage 0.0.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +166 -11
- package/README.md +174 -11
- package/dist/analyzer.d.ts +16 -3
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +15 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/cli.d.ts +6 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +49 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +94 -20
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/locations.d.ts +40 -0
- package/dist/locations.d.ts.map +1 -0
- package/dist/locations.js +100 -0
- package/dist/locations.js.map +1 -0
- package/dist/output.d.ts +38 -2
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +89 -10
- package/dist/output.js.map +1 -1
- package/dist/runner.d.ts +20 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +125 -47
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -8
package/README.ja.md
CHANGED
|
@@ -22,6 +22,7 @@ npm install -g openapi-usage
|
|
|
22
22
|
|
|
23
23
|
## 前提条件
|
|
24
24
|
|
|
25
|
+
- Node.js 22.12 以上
|
|
25
26
|
- `openapi-typescript` + `openapi-fetch` を使用したAPIクライアント
|
|
26
27
|
- `createClient()` で作成されたクライアント(変数名は自動検出)
|
|
27
28
|
- 動的パス生成なし(文字列リテラルのみ)
|
|
@@ -93,6 +94,15 @@ ignore:
|
|
|
93
94
|
- "GET /health"
|
|
94
95
|
- "GET /metrics"
|
|
95
96
|
- "* /internal/*" # ワイルドカードパターン
|
|
97
|
+
- pattern: "GET /temp/*"
|
|
98
|
+
reason: "ローカル用静的ファイル配信"
|
|
99
|
+
|
|
100
|
+
# エンドポイントごとに呼び出しを許可するディレクトリ
|
|
101
|
+
locations:
|
|
102
|
+
"* /users/**":
|
|
103
|
+
- "src/hooks/api/user/**"
|
|
104
|
+
"*":
|
|
105
|
+
- "src/hooks/api/**"
|
|
96
106
|
```
|
|
97
107
|
|
|
98
108
|
### 設定オプション
|
|
@@ -100,10 +110,21 @@ ignore:
|
|
|
100
110
|
| オプション | 説明 |
|
|
101
111
|
|------------|------|
|
|
102
112
|
| `openapi` | OpenAPI仕様ファイル(json)のパス |
|
|
103
|
-
| `src` |
|
|
104
|
-
| `output` | JSON
|
|
105
|
-
| `level` | 重大度レベル: `error` または `warn
|
|
106
|
-
| `ignore` |
|
|
113
|
+
| `src` | 解析対象ディレクトリ。単一パスまたはパスのリスト |
|
|
114
|
+
| `output` | JSON出力先パス。`--check` モードでは無視される |
|
|
115
|
+
| `level` | 重大度レベル: `error` または `warn`。起動時に検証される |
|
|
116
|
+
| `ignore` | 無視するエンドポイントのリスト。パターン文字列または `{ pattern, reason }` |
|
|
117
|
+
| `locations` | エンドポイントパターン → 呼び出しを許可するディレクトリglob |
|
|
118
|
+
| `exclude` | 解析から外すファイルのglob(cwd相対)。テストやストーリーからの呼び出しを使用箇所に数えない |
|
|
119
|
+
| `failOnStaleIgnores` | `true` にすると、効いていないignoreがあるとき `--check` を落とす(`level: error` の場合)。既定は `false` |
|
|
120
|
+
|
|
121
|
+
設定ファイルはスキーマ検証されます。不正な値(例: `level: warning`)は黙って無視されず
|
|
122
|
+
終了コード1で終了し、未知のキーは警告として報告されます:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Error: Invalid config file /app/openapi-usage.yaml: level: invalid level "warning" (expected "error" or "warn")
|
|
126
|
+
Warning: unknown config key "levell" in /app/openapi-usage.yaml (ignored)
|
|
127
|
+
```
|
|
107
128
|
|
|
108
129
|
### ignoreパターン
|
|
109
130
|
|
|
@@ -121,6 +142,111 @@ ignore:
|
|
|
121
142
|
- "* /v1/deprecated/*" # 非推奨のv1エンドポイントすべて
|
|
122
143
|
```
|
|
123
144
|
|
|
145
|
+
各エントリには理由を構造化して持たせられます。理由はレポートとJSON出力に含まれるため、
|
|
146
|
+
「なぜ未使用のまま残しているか」をYAMLコメントに閉じ込めずに済みます:
|
|
147
|
+
|
|
148
|
+
```yaml
|
|
149
|
+
ignore:
|
|
150
|
+
- "GET /health" # 従来どおり文字列も可
|
|
151
|
+
- pattern: "GET /temp/*"
|
|
152
|
+
reason: "ローカル用静的ファイル配信"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
どのエンドポイントにもマッチしないパターンは警告されます。エンドポイントの改名・削除で
|
|
156
|
+
ignoreが「死んだ」ことに気づけます:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
warning: ignore pattern "GET /sounds/*" matched no endpoint
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
ignoreは未使用のエンドポイントを除外するだけなので、マッチしたエンドポイントが全部使われて
|
|
163
|
+
いるパターンも効いていません。未使用だったエンドポイントに呼び出し元ができたときに起きます。
|
|
164
|
+
このパターンも警告するので、また未使用になったときに隠してしまう前に消せます:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
warning: ignore pattern "GET /users" matches only used endpoints
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
どちらの警告も既定では表示だけです。`failOnStaleIgnores: true` にすると、`level: error` の
|
|
171
|
+
`--check` が終了コード1で終わるので、ignoreのリストが古いまま残りません。
|
|
172
|
+
|
|
173
|
+
### ファイルの除外
|
|
174
|
+
|
|
175
|
+
テスト・ストーリー・モックからの呼び出しがあると、本番のコードが呼んでいないエンドポイントも
|
|
176
|
+
使用中に見えます。`exclude`(または `--exclude`。複数回指定可)でそのファイルを解析から外します。
|
|
177
|
+
globはcwd相対で、ワイルドカードを含まないglobはディレクトリとして扱います:
|
|
178
|
+
|
|
179
|
+
```yaml
|
|
180
|
+
exclude:
|
|
181
|
+
- "**/*.test.ts"
|
|
182
|
+
- "**/*.test.tsx"
|
|
183
|
+
- "**/*.stories.tsx"
|
|
184
|
+
- "src/__mocks__"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`--exclude` は、`--src` が `src` を置き換えるのと同じく、設定ファイルの `exclude` を置き換えます。
|
|
188
|
+
|
|
189
|
+
### 複数のソースディレクトリ
|
|
190
|
+
|
|
191
|
+
`--src` を複数回指定する、または `src` にリストを渡すと、同じ仕様に対して複数のクライアント
|
|
192
|
+
(frontend と e2e など)を解析できます。いずれかのディレクトリが呼んでいれば使用済みとして扱い、
|
|
193
|
+
サマリには「そのディレクトリから呼ばれていないエンドポイント数」も出力されます:
|
|
194
|
+
|
|
195
|
+
```yaml
|
|
196
|
+
src:
|
|
197
|
+
- packages/frontend/src
|
|
198
|
+
- e2e/api
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
openapi-usage --src packages/frontend/src --src e2e/api --check
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
───────────────────────────────────
|
|
207
|
+
Unused APIs: 1
|
|
208
|
+
- DELETE /users/{id}
|
|
209
|
+
Unused APIs per source:
|
|
210
|
+
packages/frontend/src: 2
|
|
211
|
+
e2e/api: 9
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
レポートとJSON出力の呼び出し位置パスは、カレントディレクトリからの相対パスです。
|
|
215
|
+
|
|
216
|
+
### 呼び出し位置ルール
|
|
217
|
+
|
|
218
|
+
`locations` はエンドポイントパターンに対して、呼び出しを許可するディレクトリglobを指定します。
|
|
219
|
+
「APIフックは `src/hooks/api/` に集約し、ディレクトリはAPIパスの構造に合わせる」といったルールを
|
|
220
|
+
機械で検査できます。許可ディレクトリ外からの呼び出しは違反として報告され、`level: error` の
|
|
221
|
+
`--check` では終了コード1になります:
|
|
222
|
+
|
|
223
|
+
```yaml
|
|
224
|
+
locations:
|
|
225
|
+
# endpointパターン → 呼び出しを許可するディレクトリglob
|
|
226
|
+
"* /novel/**":
|
|
227
|
+
- "src/hooks/api/novel/**"
|
|
228
|
+
- "src/app/**/_lib/**" # SSRのデータ取得
|
|
229
|
+
"* /user/**":
|
|
230
|
+
- "src/hooks/api/user/**"
|
|
231
|
+
"*": # 既定
|
|
232
|
+
- "src/hooks/api/**"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
───────────────────────────────────
|
|
237
|
+
Location violations: 1
|
|
238
|
+
- GET /novel/{novel_id} at src/components/NovelCard.tsx:12
|
|
239
|
+
allowed: src/hooks/api/novel/**, src/app/**/_lib/** (rule: "* /novel/**")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
- ディレクトリglobでは `**` はディレクトリ境界を越え、`*` は越えません
|
|
243
|
+
- ワイルドカードを含まないglob(または `/` で終わるglob)はディレクトリとして扱い、配下の全ファイルを
|
|
244
|
+
許可します。`src/hooks/api` は `src/hooks/api/**` と同じ意味になります
|
|
245
|
+
- 複数のエンドポイントパターンがマッチする場合は、最も具体的なもの(ワイルドカードを除いた
|
|
246
|
+
文字数が多いもの)が適用されるため、`"*"` は既定値として機能します
|
|
247
|
+
- globはカレントディレクトリからの相対パスと照合されます
|
|
248
|
+
- `ignore` はこのルールを免除しません(ignoreは未使用APIの報告のみを制御します)
|
|
249
|
+
|
|
124
250
|
## CLI オプション
|
|
125
251
|
|
|
126
252
|
```bash
|
|
@@ -128,7 +254,8 @@ openapi-usage [options]
|
|
|
128
254
|
|
|
129
255
|
オプション:
|
|
130
256
|
-o, --openapi <path> OpenAPI仕様ファイル(json)のパス
|
|
131
|
-
-s, --src <path>
|
|
257
|
+
-s, --src <path> 解析対象ディレクトリ(複数回指定可)
|
|
258
|
+
--exclude <glob> 解析から外すファイルのglob、cwd相対(複数回指定可)
|
|
132
259
|
--output <path> JSON出力先パス
|
|
133
260
|
--check チェックモード(未使用があればexit 1、--level errorの場合)
|
|
134
261
|
--level <level> 未使用APIの重大度レベル: "error" または "warn"(デフォルト: "error")
|
|
@@ -137,6 +264,10 @@ openapi-usage [options]
|
|
|
137
264
|
|
|
138
265
|
CLIオプションは設定ファイルの設定を上書きします。
|
|
139
266
|
|
|
267
|
+
`--check` モードでは設定ファイルの `output` は書き込まれません。lintタスクからチェックを
|
|
268
|
+
呼んでもファイルを書き換えないためです。`--check` でもJSONを書きたい場合は `--output` を
|
|
269
|
+
明示的に指定してください。
|
|
270
|
+
|
|
140
271
|
### 重大度レベル
|
|
141
272
|
|
|
142
273
|
`--level` オプションは未使用APIが検出されたときの動作を制御します:
|
|
@@ -154,6 +285,16 @@ Unused APIs: 1
|
|
|
154
285
|
- DELETE /users/{id}
|
|
155
286
|
```
|
|
156
287
|
|
|
288
|
+
`locations` を設定している場合は、サマリーの後に違反が出力されます。違反はJSON出力ファイルを
|
|
289
|
+
書き込む場合を含め、すべてのモードで表示されます:
|
|
290
|
+
|
|
291
|
+
```
|
|
292
|
+
───────────────────────────────────
|
|
293
|
+
Location violations: 1
|
|
294
|
+
- GET /users at src/api.ts:4
|
|
295
|
+
allowed: src/hooks/api/** (rule: "*")
|
|
296
|
+
```
|
|
297
|
+
|
|
157
298
|
### JSON出力(--output モード)
|
|
158
299
|
|
|
159
300
|
```json
|
|
@@ -165,22 +306,36 @@ Unused APIs: 1
|
|
|
165
306
|
"usages": [
|
|
166
307
|
{ "file": "src/pages/Users.tsx", "line": 42 }
|
|
167
308
|
]
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"method": "GET",
|
|
312
|
+
"path": "/temp/{id}",
|
|
313
|
+
"usages": [],
|
|
314
|
+
"ignored": true,
|
|
315
|
+
"reason": "ローカル用静的ファイル配信"
|
|
168
316
|
}
|
|
169
317
|
],
|
|
170
318
|
"summary": {
|
|
171
319
|
"total": 50,
|
|
172
|
-
"used":
|
|
173
|
-
"unused": 1
|
|
320
|
+
"used": 48,
|
|
321
|
+
"unused": 1,
|
|
322
|
+
"ignored": 1
|
|
174
323
|
}
|
|
175
324
|
}
|
|
176
325
|
```
|
|
177
326
|
|
|
327
|
+
ignoreされたエンドポイントも `ignored: true`(ignoreエントリに理由があれば `reason` 付き)で
|
|
328
|
+
出力に含まれ、`summary.unused` ではなく `summary.ignored` にカウントされます
|
|
329
|
+
(`used + unused + ignored === total`)。ignoreされていても `usages` は実際の呼び出し箇所を
|
|
330
|
+
そのまま出力するので、実際には使われているエンドポイントへのignoreに気づけます。
|
|
331
|
+
|
|
178
332
|
## 終了コード
|
|
179
333
|
|
|
180
334
|
| コード | 意味 |
|
|
181
335
|
|--------|------|
|
|
182
|
-
| 0 | 未使用 API
|
|
183
|
-
| 1 | 未使用 API
|
|
336
|
+
| 0 | 未使用 API・位置ルール違反なし(または `--level warn`) |
|
|
337
|
+
| 1 | 未使用 API または位置ルール違反あり(`--level error` の場合) |
|
|
338
|
+
| 1 | 設定が不正(未知の `level`、型不一致、パス不存在など) |
|
|
184
339
|
|
|
185
340
|
## ライブラリとして使用
|
|
186
341
|
|
|
@@ -202,8 +357,8 @@ if (!specResult.success) {
|
|
|
202
357
|
// エンドポイント一覧を抽出
|
|
203
358
|
const endpoints = parseOpenAPISpec(specResult.spec);
|
|
204
359
|
|
|
205
|
-
// TypeScript
|
|
206
|
-
const usages = analyzeTypeScriptFiles(endpoints, {
|
|
360
|
+
// TypeScriptファイルを解析(srcPathsで複数ディレクトリを指定可)
|
|
361
|
+
const usages = analyzeTypeScriptFiles(endpoints, { srcPaths: ["./src"] });
|
|
207
362
|
|
|
208
363
|
// JSON出力を生成
|
|
209
364
|
const output = generateJsonOutput(usages);
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ npm install -g openapi-usage
|
|
|
22
22
|
|
|
23
23
|
## Prerequisites
|
|
24
24
|
|
|
25
|
+
- Node.js 22.12 or later
|
|
25
26
|
- API client using `openapi-typescript` + `openapi-fetch`
|
|
26
27
|
- Client created with `createClient()` (variable name is auto-detected)
|
|
27
28
|
- No dynamic path generation (string literals only)
|
|
@@ -93,6 +94,15 @@ ignore:
|
|
|
93
94
|
- "GET /health"
|
|
94
95
|
- "GET /metrics"
|
|
95
96
|
- "* /internal/*" # Wildcard pattern
|
|
97
|
+
- pattern: "GET /temp/*"
|
|
98
|
+
reason: "Local static file serving"
|
|
99
|
+
|
|
100
|
+
# Restrict where each endpoint may be called from
|
|
101
|
+
locations:
|
|
102
|
+
"* /users/**":
|
|
103
|
+
- "src/hooks/api/user/**"
|
|
104
|
+
"*":
|
|
105
|
+
- "src/hooks/api/**"
|
|
96
106
|
```
|
|
97
107
|
|
|
98
108
|
### Configuration Options
|
|
@@ -100,10 +110,22 @@ ignore:
|
|
|
100
110
|
| Option | Description |
|
|
101
111
|
|--------|-------------|
|
|
102
112
|
| `openapi` | Path to OpenAPI spec file (json) |
|
|
103
|
-
| `src` | Source directory to analyze |
|
|
104
|
-
| `output` | Output JSON file path |
|
|
105
|
-
| `level` | Severity level: `error` or `warn
|
|
106
|
-
| `ignore` | List of endpoints to ignore
|
|
113
|
+
| `src` | Source directory to analyze. A single path, or a list of paths |
|
|
114
|
+
| `output` | Output JSON file path. Ignored in `--check` mode |
|
|
115
|
+
| `level` | Severity level: `error` or `warn`. Validated at startup |
|
|
116
|
+
| `ignore` | List of endpoints to ignore. A pattern string, or `{ pattern, reason }` |
|
|
117
|
+
| `locations` | Endpoint pattern → directory globs the endpoint may be called from |
|
|
118
|
+
| `exclude` | File globs (relative to cwd) to skip, so calls from tests or stories do not count as usage |
|
|
119
|
+
| `failOnStaleIgnores` | `true` makes `--check` fail (with `level: error`) when an ignore entry has no effect. Default `false` |
|
|
120
|
+
|
|
121
|
+
The config file is schema-validated. An invalid value (for example `level: warning`)
|
|
122
|
+
exits with code 1 instead of being silently ignored, and unknown keys are reported
|
|
123
|
+
as warnings:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Error: Invalid config file /app/openapi-usage.yaml: level: invalid level "warning" (expected "error" or "warn")
|
|
127
|
+
Warning: unknown config key "levell" in /app/openapi-usage.yaml (ignored)
|
|
128
|
+
```
|
|
107
129
|
|
|
108
130
|
### Ignore Patterns
|
|
109
131
|
|
|
@@ -121,6 +143,118 @@ ignore:
|
|
|
121
143
|
- "* /v1/deprecated/*" # All deprecated v1 endpoints
|
|
122
144
|
```
|
|
123
145
|
|
|
146
|
+
An entry can also carry a machine-readable reason. The reason shows up in the
|
|
147
|
+
report and in the JSON output, so "why is this left unused" does not have to live
|
|
148
|
+
in a YAML comment:
|
|
149
|
+
|
|
150
|
+
```yaml
|
|
151
|
+
ignore:
|
|
152
|
+
- "GET /health" # Plain strings still work
|
|
153
|
+
- pattern: "GET /temp/*"
|
|
154
|
+
reason: "Local static file serving"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Patterns that match no endpoint are reported, so an ignore entry left behind by a
|
|
158
|
+
renamed or deleted endpoint does not stay unnoticed:
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
warning: ignore pattern "GET /sounds/*" matched no endpoint
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
An ignore entry only exempts unused endpoints, so an entry whose endpoints are all
|
|
165
|
+
called has no effect either. This happens when an endpoint that used to be unused
|
|
166
|
+
gets a caller. It is reported too, so the entry can be removed before it hides the
|
|
167
|
+
endpoint becoming unused again:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
warning: ignore pattern "GET /users" matches only used endpoints
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Both warnings are informational by default. Set `failOnStaleIgnores: true` to make
|
|
174
|
+
`--check` exit with code 1 on them (with `level: error`), so the ignore list
|
|
175
|
+
cannot grow stale.
|
|
176
|
+
|
|
177
|
+
### Excluding Files
|
|
178
|
+
|
|
179
|
+
Calls from tests, stories and mocks make an endpoint look used even when no
|
|
180
|
+
production code calls it. Pass `exclude` (or `--exclude`, repeatable) to skip those
|
|
181
|
+
files. Globs are relative to the current directory, and a glob without a wildcard
|
|
182
|
+
is treated as a directory:
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
exclude:
|
|
186
|
+
- "**/*.test.ts"
|
|
187
|
+
- "**/*.test.tsx"
|
|
188
|
+
- "**/*.stories.tsx"
|
|
189
|
+
- "src/__mocks__"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`--exclude` replaces the config's `exclude`, the same way `--src` replaces `src`.
|
|
193
|
+
|
|
194
|
+
### Multiple Source Directories
|
|
195
|
+
|
|
196
|
+
Pass `--src` more than once, or give `src` a list, to analyze several clients
|
|
197
|
+
against the same spec — for example a frontend and an e2e suite. An endpoint is
|
|
198
|
+
counted as used when any of the directories calls it, and the summary also
|
|
199
|
+
reports how many endpoints each directory does not call:
|
|
200
|
+
|
|
201
|
+
```yaml
|
|
202
|
+
src:
|
|
203
|
+
- packages/frontend/src
|
|
204
|
+
- e2e/api
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
openapi-usage --src packages/frontend/src --src e2e/api --check
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
───────────────────────────────────
|
|
213
|
+
Unused APIs: 1
|
|
214
|
+
- DELETE /users/{id}
|
|
215
|
+
Unused APIs per source:
|
|
216
|
+
packages/frontend/src: 2
|
|
217
|
+
e2e/api: 9
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Call-site paths in the report and in the JSON output are relative to the current
|
|
221
|
+
working directory.
|
|
222
|
+
|
|
223
|
+
### Call-site Location Rules
|
|
224
|
+
|
|
225
|
+
`locations` maps an endpoint pattern to the directory globs its call sites are
|
|
226
|
+
allowed to live in — for example "API hooks belong under `src/hooks/api/`, mirroring
|
|
227
|
+
the API path structure". A call from anywhere else is reported as a violation, and
|
|
228
|
+
fails `--check` with `level: error`:
|
|
229
|
+
|
|
230
|
+
```yaml
|
|
231
|
+
locations:
|
|
232
|
+
# endpoint pattern → allowed call-site directory globs
|
|
233
|
+
"* /novel/**":
|
|
234
|
+
- "src/hooks/api/novel/**"
|
|
235
|
+
- "src/app/**/_lib/**" # SSR data fetching
|
|
236
|
+
"* /user/**":
|
|
237
|
+
- "src/hooks/api/user/**"
|
|
238
|
+
"*": # Default
|
|
239
|
+
- "src/hooks/api/**"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
───────────────────────────────────
|
|
244
|
+
Location violations: 1
|
|
245
|
+
- GET /novel/{novel_id} at src/components/NovelCard.tsx:12
|
|
246
|
+
allowed: src/hooks/api/novel/**, src/app/**/_lib/** (rule: "* /novel/**")
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- In directory globs, `**` crosses directory boundaries and `*` does not
|
|
250
|
+
- A glob without wildcards (or ending with `/`) is treated as a directory and allows
|
|
251
|
+
every file under it, so `src/hooks/api` behaves like `src/hooks/api/**`
|
|
252
|
+
- When several endpoint patterns match, the most specific one wins (the one with
|
|
253
|
+
the most non-wildcard characters), so `"*"` acts as a default
|
|
254
|
+
- Globs are matched against paths relative to the current working directory
|
|
255
|
+
- `ignore` does not exempt call sites from these rules: it only controls
|
|
256
|
+
unused-API reporting
|
|
257
|
+
|
|
124
258
|
## CLI Options
|
|
125
259
|
|
|
126
260
|
```bash
|
|
@@ -128,7 +262,8 @@ openapi-usage [options]
|
|
|
128
262
|
|
|
129
263
|
Options:
|
|
130
264
|
-o, --openapi <path> Path to OpenAPI spec file (json)
|
|
131
|
-
-s, --src <path> Source directory to analyze
|
|
265
|
+
-s, --src <path> Source directory to analyze (repeatable)
|
|
266
|
+
--exclude <glob> Glob of files to skip, relative to cwd (repeatable)
|
|
132
267
|
--output <path> Output JSON file path
|
|
133
268
|
--check Check mode (exit 1 if unused APIs exist with --level error)
|
|
134
269
|
--level <level> Set severity level for unused APIs: "error" or "warn" (default: "error")
|
|
@@ -137,6 +272,10 @@ Options:
|
|
|
137
272
|
|
|
138
273
|
CLI options override configuration file settings.
|
|
139
274
|
|
|
275
|
+
In `--check` mode the `output` file from the config file is **not** written, so
|
|
276
|
+
running the check as part of a lint task has no side effects. Pass `--output`
|
|
277
|
+
explicitly when you want the JSON written anyway.
|
|
278
|
+
|
|
140
279
|
### Severity Level
|
|
141
280
|
|
|
142
281
|
The `--level` option controls the behavior when unused APIs are detected:
|
|
@@ -154,6 +293,16 @@ Unused APIs: 1
|
|
|
154
293
|
- DELETE /users/{id}
|
|
155
294
|
```
|
|
156
295
|
|
|
296
|
+
With `locations` configured, violations are listed after the summary. They are
|
|
297
|
+
printed in every mode, including when the JSON output file is written:
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
───────────────────────────────────
|
|
301
|
+
Location violations: 1
|
|
302
|
+
- GET /users at src/api.ts:4
|
|
303
|
+
allowed: src/hooks/api/** (rule: "*")
|
|
304
|
+
```
|
|
305
|
+
|
|
157
306
|
### JSON Output (--output mode)
|
|
158
307
|
|
|
159
308
|
```json
|
|
@@ -165,22 +314,36 @@ Unused APIs: 1
|
|
|
165
314
|
"usages": [
|
|
166
315
|
{ "file": "src/pages/Users.tsx", "line": 42 }
|
|
167
316
|
]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"method": "GET",
|
|
320
|
+
"path": "/temp/{id}",
|
|
321
|
+
"usages": [],
|
|
322
|
+
"ignored": true,
|
|
323
|
+
"reason": "Local static file serving"
|
|
168
324
|
}
|
|
169
325
|
],
|
|
170
326
|
"summary": {
|
|
171
327
|
"total": 50,
|
|
172
|
-
"used":
|
|
173
|
-
"unused": 1
|
|
328
|
+
"used": 48,
|
|
329
|
+
"unused": 1,
|
|
330
|
+
"ignored": 1
|
|
174
331
|
}
|
|
175
332
|
}
|
|
176
333
|
```
|
|
177
334
|
|
|
335
|
+
Ignored endpoints are included with `ignored: true` (plus `reason` when the ignore
|
|
336
|
+
entry has one) and are counted in `summary.ignored` instead of `summary.unused`,
|
|
337
|
+
so `used + unused + ignored === total`. Their `usages` are still listed, so an
|
|
338
|
+
ignore entry for an endpoint that is actually called stays visible.
|
|
339
|
+
|
|
178
340
|
## Exit Codes
|
|
179
341
|
|
|
180
342
|
| Code | Meaning |
|
|
181
343
|
|------|---------|
|
|
182
|
-
| 0 | No unused APIs (or `--level warn`) |
|
|
183
|
-
| 1 | Unused APIs exist (with `--level error`) |
|
|
344
|
+
| 0 | No unused APIs and no location violations (or `--level warn`) |
|
|
345
|
+
| 1 | Unused APIs or location violations exist (with `--level error`) |
|
|
346
|
+
| 1 | Invalid configuration (unknown `level`, wrong value types, missing paths) |
|
|
184
347
|
|
|
185
348
|
## Library Usage
|
|
186
349
|
|
|
@@ -202,8 +365,8 @@ if (!specResult.success) {
|
|
|
202
365
|
// Extract endpoint list
|
|
203
366
|
const endpoints = parseOpenAPISpec(specResult.spec);
|
|
204
367
|
|
|
205
|
-
// Analyze TypeScript files
|
|
206
|
-
const usages = analyzeTypeScriptFiles(endpoints, {
|
|
368
|
+
// Analyze TypeScript files (srcPaths accepts multiple directories)
|
|
369
|
+
const usages = analyzeTypeScriptFiles(endpoints, { srcPaths: ["./src"] });
|
|
207
370
|
|
|
208
371
|
// Generate JSON output
|
|
209
372
|
const output = generateJsonOutput(usages);
|
package/dist/analyzer.d.ts
CHANGED
|
@@ -3,8 +3,21 @@ import { type Usage } from "./types.js";
|
|
|
3
3
|
export { extractStringLiterals } from "./extractors.js";
|
|
4
4
|
export { findMatchingEndpoint } from "./path-matcher.js";
|
|
5
5
|
export interface AnalyzeOptions {
|
|
6
|
-
|
|
6
|
+
/** 解析対象のソースディレクトリ(単一指定) */
|
|
7
|
+
srcPath?: string;
|
|
8
|
+
/** 解析対象のソースディレクトリ(複数指定) */
|
|
9
|
+
srcPaths?: string[];
|
|
7
10
|
tsConfigPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* 使用箇所のファイルパスを相対化する基準ディレクトリ
|
|
13
|
+
* 省略時は process.cwd()
|
|
14
|
+
*/
|
|
15
|
+
basePath?: string;
|
|
16
|
+
/**
|
|
17
|
+
* 解析から外すファイルのglob(basePath 相対)。ワイルドカードを含まないglobはディレクトリとみなす
|
|
18
|
+
* テストやストーリーからの呼び出しを使用箇所に数えないために使う
|
|
19
|
+
*/
|
|
20
|
+
exclude?: string[];
|
|
8
21
|
}
|
|
9
22
|
/**
|
|
10
23
|
* TypeScriptファイル群を解析してAPI呼び出し箇所を検出する
|
|
@@ -22,9 +35,9 @@ export declare function findOpenApiFetchClients(sourceFile: SourceFile): Set<str
|
|
|
22
35
|
/**
|
|
23
36
|
* 単一のソースファイルを解析してAPI呼び出しを検出する
|
|
24
37
|
* @param sourceFile - 解析対象のソースファイル
|
|
25
|
-
* @param
|
|
38
|
+
* @param basePath - 使用箇所のファイルパスを相対化する基準ディレクトリ
|
|
26
39
|
* @param endpoints - OpenAPIエンドポイント一覧
|
|
27
40
|
* @param usages - 使用箇所を記録するマップ(副作用で更新)
|
|
28
41
|
*/
|
|
29
|
-
export declare function analyzeSourceFile(sourceFile: SourceFile,
|
|
42
|
+
export declare function analyzeSourceFile(sourceFile: SourceFile, basePath: string, endpoints: Map<string, Set<string>>, usages: Map<string, Usage[]>): void;
|
|
30
43
|
//# sourceMappingURL=analyzer.d.ts.map
|
package/dist/analyzer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAI/E,OAAO,EAAiC,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC9B,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EACnC,OAAO,EAAE,cAAc,GACrB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAqBtB;AA2CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAyB3E;AA0DD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EACnC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,GAC1B,IAAI,CAiBN"}
|
package/dist/analyzer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { relative, resolve } from "node:path";
|
|
2
2
|
import { Node, Project } from "ts-morph";
|
|
3
3
|
import { extractStringLiterals } from "./extractors.js";
|
|
4
|
+
import { matchPathGlob } from "./locations.js";
|
|
4
5
|
import { findMatchingEndpoint } from "./path-matcher.js";
|
|
5
6
|
import { HTTP_METHODS } from "./types.js";
|
|
6
7
|
export { extractStringLiterals } from "./extractors.js";
|
|
@@ -12,12 +13,20 @@ export { findMatchingEndpoint } from "./path-matcher.js";
|
|
|
12
13
|
* @returns エンドポイントごとの使用箇所マップ
|
|
13
14
|
*/
|
|
14
15
|
export function analyzeTypeScriptFiles(endpoints, options) {
|
|
15
|
-
const { srcPath, tsConfigPath } = options;
|
|
16
|
+
const { srcPath, srcPaths, tsConfigPath, basePath, exclude = [] } = options;
|
|
17
|
+
const roots = [...(srcPaths ?? []), ...(srcPath ? [srcPath] : [])];
|
|
16
18
|
const project = createProject(tsConfigPath);
|
|
17
|
-
|
|
19
|
+
for (const root of roots) {
|
|
20
|
+
project.addSourceFilesAtPaths([`${root}/**/*.ts`, `${root}/**/*.tsx`]);
|
|
21
|
+
}
|
|
18
22
|
const usages = initializeUsagesMap(endpoints);
|
|
23
|
+
const relativeBase = basePath ?? process.cwd();
|
|
19
24
|
for (const sourceFile of project.getSourceFiles()) {
|
|
20
|
-
|
|
25
|
+
const file = relative(relativeBase, sourceFile.getFilePath());
|
|
26
|
+
if (exclude.some((glob) => matchPathGlob(file, glob))) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
analyzeSourceFile(sourceFile, relativeBase, endpoints, usages);
|
|
21
30
|
}
|
|
22
31
|
return usages;
|
|
23
32
|
}
|
|
@@ -119,13 +128,13 @@ function recordUsage(key, usage, usages, endpoints) {
|
|
|
119
128
|
/**
|
|
120
129
|
* 単一のソースファイルを解析してAPI呼び出しを検出する
|
|
121
130
|
* @param sourceFile - 解析対象のソースファイル
|
|
122
|
-
* @param
|
|
131
|
+
* @param basePath - 使用箇所のファイルパスを相対化する基準ディレクトリ
|
|
123
132
|
* @param endpoints - OpenAPIエンドポイント一覧
|
|
124
133
|
* @param usages - 使用箇所を記録するマップ(副作用で更新)
|
|
125
134
|
*/
|
|
126
|
-
export function analyzeSourceFile(sourceFile,
|
|
135
|
+
export function analyzeSourceFile(sourceFile, basePath, endpoints, usages) {
|
|
127
136
|
const filePath = sourceFile.getFilePath();
|
|
128
|
-
const relativeFilePath = relative(resolve(
|
|
137
|
+
const relativeFilePath = relative(resolve(basePath), filePath);
|
|
129
138
|
const clientNames = findOpenApiFetchClients(sourceFile);
|
|
130
139
|
sourceFile.forEachDescendant((node) => {
|
|
131
140
|
const apiCall = tryExtractApiCall(node, sourceFile, clientNames);
|
package/dist/analyzer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAuB,IAAI,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAA+B,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAuB,IAAI,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAA+B,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAoBzD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACrC,SAAmC,EACnC,OAAuB;IAEvB,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAC5E,MAAM,K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CAAC,IAAI,EAAE,CAAC;QAE7D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,UAAU,IAAI,SAAS,EAAE,CAAC;YACjD,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -2,11 +2,15 @@ import { Command } from "commander";
|
|
|
2
2
|
export type SeverityLevel = "error" | "warn";
|
|
3
3
|
export interface CliOptions {
|
|
4
4
|
openapi?: string;
|
|
5
|
-
src
|
|
5
|
+
/** 解析対象ディレクトリ。--src を複数回指定すると配列になる */
|
|
6
|
+
src?: string | string[];
|
|
6
7
|
output?: string;
|
|
7
8
|
check?: boolean;
|
|
8
|
-
|
|
9
|
+
/** "error" | "warn"。不正値は起動時に検証してエラー終了する */
|
|
10
|
+
level?: string;
|
|
9
11
|
config?: string;
|
|
12
|
+
/** 解析から外すファイルのglob。--exclude を複数回指定できる */
|
|
13
|
+
exclude?: string[];
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* CLIプログラムを作成する
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,UAAU;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,UAAU;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAMD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAsBvC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,CAOvE"}
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
function collect(value, previous) {
|
|
3
|
+
return [...(previous ?? []), value];
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* CLIプログラムを作成する
|
|
4
7
|
* @returns Commanderプログラムインスタンス
|
|
@@ -8,7 +11,8 @@ export function createProgram() {
|
|
|
8
11
|
.name("openapi-usage")
|
|
9
12
|
.description("Analyze API usage based on OpenAPI spec")
|
|
10
13
|
.option("-o, --openapi <path>", "Path to OpenAPI spec file")
|
|
11
|
-
.option("-s, --src <path>", "Path to source directory")
|
|
14
|
+
.option("-s, --src <path>", "Path to source directory (repeatable)", collect)
|
|
15
|
+
.option("--exclude <glob>", "Glob of files to skip, relative to cwd (repeatable)", collect)
|
|
12
16
|
.option("--output <path>", "Output JSON file path")
|
|
13
17
|
.option("--check", "Check mode (exit 1 if unused APIs exist)")
|
|
14
18
|
.option("--level <level>", 'Severity level for unused APIs: "error" or "warn"')
|