openapi-usage 0.0.4 → 0.1.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 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,19 @@ 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
+
119
+ 設定ファイルはスキーマ検証されます。不正な値(例: `level: warning`)は黙って無視されず
120
+ 終了コード1で終了し、未知のキーは警告として報告されます:
121
+
122
+ ```
123
+ Error: Invalid config file /app/openapi-usage.yaml: level: invalid level "warning" (expected "error" or "warn")
124
+ Warning: unknown config key "levell" in /app/openapi-usage.yaml (ignored)
125
+ ```
107
126
 
108
127
  ### ignoreパターン
109
128
 
@@ -121,6 +140,84 @@ ignore:
121
140
  - "* /v1/deprecated/*" # 非推奨のv1エンドポイントすべて
122
141
  ```
123
142
 
143
+ 各エントリには理由を構造化して持たせられます。理由はレポートとJSON出力に含まれるため、
144
+ 「なぜ未使用のまま残しているか」をYAMLコメントに閉じ込めずに済みます:
145
+
146
+ ```yaml
147
+ ignore:
148
+ - "GET /health" # 従来どおり文字列も可
149
+ - pattern: "GET /temp/*"
150
+ reason: "ローカル用静的ファイル配信"
151
+ ```
152
+
153
+ どのエンドポイントにもマッチしないパターンは警告されます。エンドポイントの改名・削除で
154
+ ignoreが「死んだ」ことに気づけます:
155
+
156
+ ```
157
+ warning: ignore pattern "GET /sounds/*" matched no endpoint
158
+ ```
159
+
160
+ ### 複数のソースディレクトリ
161
+
162
+ `--src` を複数回指定する、または `src` にリストを渡すと、同じ仕様に対して複数のクライアント
163
+ (frontend と e2e など)を解析できます。いずれかのディレクトリが呼んでいれば使用済みとして扱い、
164
+ サマリには「そのディレクトリから呼ばれていないエンドポイント数」も出力されます:
165
+
166
+ ```yaml
167
+ src:
168
+ - packages/frontend/src
169
+ - e2e/api
170
+ ```
171
+
172
+ ```bash
173
+ openapi-usage --src packages/frontend/src --src e2e/api --check
174
+ ```
175
+
176
+ ```
177
+ ───────────────────────────────────
178
+ Unused APIs: 1
179
+ - DELETE /users/{id}
180
+ Unused APIs per source:
181
+ packages/frontend/src: 2
182
+ e2e/api: 9
183
+ ```
184
+
185
+ レポートとJSON出力の呼び出し位置パスは、カレントディレクトリからの相対パスです。
186
+
187
+ ### 呼び出し位置ルール
188
+
189
+ `locations` はエンドポイントパターンに対して、呼び出しを許可するディレクトリglobを指定します。
190
+ 「APIフックは `src/hooks/api/` に集約し、ディレクトリはAPIパスの構造に合わせる」といったルールを
191
+ 機械で検査できます。許可ディレクトリ外からの呼び出しは違反として報告され、`level: error` の
192
+ `--check` では終了コード1になります:
193
+
194
+ ```yaml
195
+ locations:
196
+ # endpointパターン → 呼び出しを許可するディレクトリglob
197
+ "* /novel/**":
198
+ - "src/hooks/api/novel/**"
199
+ - "src/app/**/_lib/**" # SSRのデータ取得
200
+ "* /user/**":
201
+ - "src/hooks/api/user/**"
202
+ "*": # 既定
203
+ - "src/hooks/api/**"
204
+ ```
205
+
206
+ ```
207
+ ───────────────────────────────────
208
+ Location violations: 1
209
+ - GET /novel/{novel_id} at src/components/NovelCard.tsx:12
210
+ allowed: src/hooks/api/novel/**, src/app/**/_lib/** (rule: "* /novel/**")
211
+ ```
212
+
213
+ - ディレクトリglobでは `**` はディレクトリ境界を越え、`*` は越えません
214
+ - ワイルドカードを含まないglob(または `/` で終わるglob)はディレクトリとして扱い、配下の全ファイルを
215
+ 許可します。`src/hooks/api` は `src/hooks/api/**` と同じ意味になります
216
+ - 複数のエンドポイントパターンがマッチする場合は、最も具体的なもの(ワイルドカードを除いた
217
+ 文字数が多いもの)が適用されるため、`"*"` は既定値として機能します
218
+ - globはカレントディレクトリからの相対パスと照合されます
219
+ - `ignore` はこのルールを免除しません(ignoreは未使用APIの報告のみを制御します)
220
+
124
221
  ## CLI オプション
125
222
 
126
223
  ```bash
@@ -128,7 +225,7 @@ openapi-usage [options]
128
225
 
129
226
  オプション:
130
227
  -o, --openapi <path> OpenAPI仕様ファイル(json)のパス
131
- -s, --src <path> 解析対象ディレクトリ
228
+ -s, --src <path> 解析対象ディレクトリ(複数回指定可)
132
229
  --output <path> JSON出力先パス
133
230
  --check チェックモード(未使用があればexit 1、--level errorの場合)
134
231
  --level <level> 未使用APIの重大度レベル: "error" または "warn"(デフォルト: "error")
@@ -137,6 +234,10 @@ openapi-usage [options]
137
234
 
138
235
  CLIオプションは設定ファイルの設定を上書きします。
139
236
 
237
+ `--check` モードでは設定ファイルの `output` は書き込まれません。lintタスクからチェックを
238
+ 呼んでもファイルを書き換えないためです。`--check` でもJSONを書きたい場合は `--output` を
239
+ 明示的に指定してください。
240
+
140
241
  ### 重大度レベル
141
242
 
142
243
  `--level` オプションは未使用APIが検出されたときの動作を制御します:
@@ -154,6 +255,16 @@ Unused APIs: 1
154
255
  - DELETE /users/{id}
155
256
  ```
156
257
 
258
+ `locations` を設定している場合は、サマリーの後に違反が出力されます。違反はJSON出力ファイルを
259
+ 書き込む場合を含め、すべてのモードで表示されます:
260
+
261
+ ```
262
+ ───────────────────────────────────
263
+ Location violations: 1
264
+ - GET /users at src/api.ts:4
265
+ allowed: src/hooks/api/** (rule: "*")
266
+ ```
267
+
157
268
  ### JSON出力(--output モード)
158
269
 
159
270
  ```json
@@ -165,22 +276,36 @@ Unused APIs: 1
165
276
  "usages": [
166
277
  { "file": "src/pages/Users.tsx", "line": 42 }
167
278
  ]
279
+ },
280
+ {
281
+ "method": "GET",
282
+ "path": "/temp/{id}",
283
+ "usages": [],
284
+ "ignored": true,
285
+ "reason": "ローカル用静的ファイル配信"
168
286
  }
169
287
  ],
170
288
  "summary": {
171
289
  "total": 50,
172
- "used": 49,
173
- "unused": 1
290
+ "used": 48,
291
+ "unused": 1,
292
+ "ignored": 1
174
293
  }
175
294
  }
176
295
  ```
177
296
 
297
+ ignoreされたエンドポイントも `ignored: true`(ignoreエントリに理由があれば `reason` 付き)で
298
+ 出力に含まれ、`summary.unused` ではなく `summary.ignored` にカウントされます
299
+ (`used + unused + ignored === total`)。ignoreされていても `usages` は実際の呼び出し箇所を
300
+ そのまま出力するので、実際には使われているエンドポイントへのignoreに気づけます。
301
+
178
302
  ## 終了コード
179
303
 
180
304
  | コード | 意味 |
181
305
  |--------|------|
182
- | 0 | 未使用 API なし(または `--level warn`) |
183
- | 1 | 未使用 API あり(`--level error` の場合) |
306
+ | 0 | 未使用 API・位置ルール違反なし(または `--level warn`) |
307
+ | 1 | 未使用 API または位置ルール違反あり(`--level error` の場合) |
308
+ | 1 | 設定が不正(未知の `level`、型不一致、パス不存在など) |
184
309
 
185
310
  ## ライブラリとして使用
186
311
 
@@ -202,8 +327,8 @@ if (!specResult.success) {
202
327
  // エンドポイント一覧を抽出
203
328
  const endpoints = parseOpenAPISpec(specResult.spec);
204
329
 
205
- // TypeScriptファイルを解析
206
- const usages = analyzeTypeScriptFiles(endpoints, { srcPath: "./src" });
330
+ // TypeScriptファイルを解析(srcPathsで複数ディレクトリを指定可)
331
+ const usages = analyzeTypeScriptFiles(endpoints, { srcPaths: ["./src"] });
207
332
 
208
333
  // JSON出力を生成
209
334
  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,20 @@ 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 (supports wildcards) |
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
+
119
+ The config file is schema-validated. An invalid value (for example `level: warning`)
120
+ exits with code 1 instead of being silently ignored, and unknown keys are reported
121
+ as warnings:
122
+
123
+ ```
124
+ Error: Invalid config file /app/openapi-usage.yaml: level: invalid level "warning" (expected "error" or "warn")
125
+ Warning: unknown config key "levell" in /app/openapi-usage.yaml (ignored)
126
+ ```
107
127
 
108
128
  ### Ignore Patterns
109
129
 
@@ -121,6 +141,88 @@ ignore:
121
141
  - "* /v1/deprecated/*" # All deprecated v1 endpoints
122
142
  ```
123
143
 
144
+ An entry can also carry a machine-readable reason. The reason shows up in the
145
+ report and in the JSON output, so "why is this left unused" does not have to live
146
+ in a YAML comment:
147
+
148
+ ```yaml
149
+ ignore:
150
+ - "GET /health" # Plain strings still work
151
+ - pattern: "GET /temp/*"
152
+ reason: "Local static file serving"
153
+ ```
154
+
155
+ Patterns that match no endpoint are reported, so an ignore entry left behind by a
156
+ renamed or deleted endpoint does not stay unnoticed:
157
+
158
+ ```
159
+ warning: ignore pattern "GET /sounds/*" matched no endpoint
160
+ ```
161
+
162
+ ### Multiple Source Directories
163
+
164
+ Pass `--src` more than once, or give `src` a list, to analyze several clients
165
+ against the same spec — for example a frontend and an e2e suite. An endpoint is
166
+ counted as used when any of the directories calls it, and the summary also
167
+ reports how many endpoints each directory does not call:
168
+
169
+ ```yaml
170
+ src:
171
+ - packages/frontend/src
172
+ - e2e/api
173
+ ```
174
+
175
+ ```bash
176
+ openapi-usage --src packages/frontend/src --src e2e/api --check
177
+ ```
178
+
179
+ ```
180
+ ───────────────────────────────────
181
+ Unused APIs: 1
182
+ - DELETE /users/{id}
183
+ Unused APIs per source:
184
+ packages/frontend/src: 2
185
+ e2e/api: 9
186
+ ```
187
+
188
+ Call-site paths in the report and in the JSON output are relative to the current
189
+ working directory.
190
+
191
+ ### Call-site Location Rules
192
+
193
+ `locations` maps an endpoint pattern to the directory globs its call sites are
194
+ allowed to live in — for example "API hooks belong under `src/hooks/api/`, mirroring
195
+ the API path structure". A call from anywhere else is reported as a violation, and
196
+ fails `--check` with `level: error`:
197
+
198
+ ```yaml
199
+ locations:
200
+ # endpoint pattern → allowed call-site directory globs
201
+ "* /novel/**":
202
+ - "src/hooks/api/novel/**"
203
+ - "src/app/**/_lib/**" # SSR data fetching
204
+ "* /user/**":
205
+ - "src/hooks/api/user/**"
206
+ "*": # Default
207
+ - "src/hooks/api/**"
208
+ ```
209
+
210
+ ```
211
+ ───────────────────────────────────
212
+ Location violations: 1
213
+ - GET /novel/{novel_id} at src/components/NovelCard.tsx:12
214
+ allowed: src/hooks/api/novel/**, src/app/**/_lib/** (rule: "* /novel/**")
215
+ ```
216
+
217
+ - In directory globs, `**` crosses directory boundaries and `*` does not
218
+ - A glob without wildcards (or ending with `/`) is treated as a directory and allows
219
+ every file under it, so `src/hooks/api` behaves like `src/hooks/api/**`
220
+ - When several endpoint patterns match, the most specific one wins (the one with
221
+ the most non-wildcard characters), so `"*"` acts as a default
222
+ - Globs are matched against paths relative to the current working directory
223
+ - `ignore` does not exempt call sites from these rules: it only controls
224
+ unused-API reporting
225
+
124
226
  ## CLI Options
125
227
 
126
228
  ```bash
@@ -128,7 +230,7 @@ openapi-usage [options]
128
230
 
129
231
  Options:
130
232
  -o, --openapi <path> Path to OpenAPI spec file (json)
131
- -s, --src <path> Source directory to analyze
233
+ -s, --src <path> Source directory to analyze (repeatable)
132
234
  --output <path> Output JSON file path
133
235
  --check Check mode (exit 1 if unused APIs exist with --level error)
134
236
  --level <level> Set severity level for unused APIs: "error" or "warn" (default: "error")
@@ -137,6 +239,10 @@ Options:
137
239
 
138
240
  CLI options override configuration file settings.
139
241
 
242
+ In `--check` mode the `output` file from the config file is **not** written, so
243
+ running the check as part of a lint task has no side effects. Pass `--output`
244
+ explicitly when you want the JSON written anyway.
245
+
140
246
  ### Severity Level
141
247
 
142
248
  The `--level` option controls the behavior when unused APIs are detected:
@@ -154,6 +260,16 @@ Unused APIs: 1
154
260
  - DELETE /users/{id}
155
261
  ```
156
262
 
263
+ With `locations` configured, violations are listed after the summary. They are
264
+ printed in every mode, including when the JSON output file is written:
265
+
266
+ ```
267
+ ───────────────────────────────────
268
+ Location violations: 1
269
+ - GET /users at src/api.ts:4
270
+ allowed: src/hooks/api/** (rule: "*")
271
+ ```
272
+
157
273
  ### JSON Output (--output mode)
158
274
 
159
275
  ```json
@@ -165,22 +281,36 @@ Unused APIs: 1
165
281
  "usages": [
166
282
  { "file": "src/pages/Users.tsx", "line": 42 }
167
283
  ]
284
+ },
285
+ {
286
+ "method": "GET",
287
+ "path": "/temp/{id}",
288
+ "usages": [],
289
+ "ignored": true,
290
+ "reason": "Local static file serving"
168
291
  }
169
292
  ],
170
293
  "summary": {
171
294
  "total": 50,
172
- "used": 49,
173
- "unused": 1
295
+ "used": 48,
296
+ "unused": 1,
297
+ "ignored": 1
174
298
  }
175
299
  }
176
300
  ```
177
301
 
302
+ Ignored endpoints are included with `ignored: true` (plus `reason` when the ignore
303
+ entry has one) and are counted in `summary.ignored` instead of `summary.unused`,
304
+ so `used + unused + ignored === total`. Their `usages` are still listed, so an
305
+ ignore entry for an endpoint that is actually called stays visible.
306
+
178
307
  ## Exit Codes
179
308
 
180
309
  | Code | Meaning |
181
310
  |------|---------|
182
- | 0 | No unused APIs (or `--level warn`) |
183
- | 1 | Unused APIs exist (with `--level error`) |
311
+ | 0 | No unused APIs and no location violations (or `--level warn`) |
312
+ | 1 | Unused APIs or location violations exist (with `--level error`) |
313
+ | 1 | Invalid configuration (unknown `level`, wrong value types, missing paths) |
184
314
 
185
315
  ## Library Usage
186
316
 
@@ -202,8 +332,8 @@ if (!specResult.success) {
202
332
  // Extract endpoint list
203
333
  const endpoints = parseOpenAPISpec(specResult.spec);
204
334
 
205
- // Analyze TypeScript files
206
- const usages = analyzeTypeScriptFiles(endpoints, { srcPath: "./src" });
335
+ // Analyze TypeScript files (srcPaths accepts multiple directories)
336
+ const usages = analyzeTypeScriptFiles(endpoints, { srcPaths: ["./src"] });
207
337
 
208
338
  // Generate JSON output
209
339
  const output = generateJsonOutput(usages);
@@ -3,8 +3,16 @@ 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
- srcPath: string;
6
+ /** 解析対象のソースディレクトリ(単一指定) */
7
+ srcPath?: string;
8
+ /** 解析対象のソースディレクトリ(複数指定) */
9
+ srcPaths?: string[];
7
10
  tsConfigPath?: string;
11
+ /**
12
+ * 使用箇所のファイルパスを相対化する基準ディレクトリ
13
+ * 省略時は process.cwd()
14
+ */
15
+ basePath?: string;
8
16
  }
9
17
  /**
10
18
  * TypeScriptファイル群を解析してAPI呼び出し箇所を検出する
@@ -22,9 +30,9 @@ export declare function findOpenApiFetchClients(sourceFile: SourceFile): Set<str
22
30
  /**
23
31
  * 単一のソースファイルを解析してAPI呼び出しを検出する
24
32
  * @param sourceFile - 解析対象のソースファイル
25
- * @param srcPath - ソースディレクトリのパス
33
+ * @param basePath - 使用箇所のファイルパスを相対化する基準ディレクトリ
26
34
  * @param endpoints - OpenAPIエンドポイント一覧
27
35
  * @param usages - 使用箇所を記録するマップ(副作用で更新)
28
36
  */
29
- export declare function analyzeSourceFile(sourceFile: SourceFile, srcPath: string, endpoints: Map<string, Set<string>>, usages: Map<string, Usage[]>): void;
37
+ export declare function analyzeSourceFile(sourceFile: SourceFile, basePath: string, endpoints: Map<string, Set<string>>, usages: Map<string, Usage[]>): void;
30
38
  //# sourceMappingURL=analyzer.d.ts.map
@@ -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;AAG/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,OAA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AO,EAAE,cAAc,GACrB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAiBtB;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
@@ -12,12 +12,16 @@ export { findMatchingEndpoint } from "./path-matcher.js";
12
12
  * @returns エンドポイントごとの使用箇所マップ
13
13
  */
14
14
  export function analyzeTypeScriptFiles(endpoints, options) {
15
- const { srcPath, tsConfigPath } = options;
15
+ const { srcPath, srcPaths, tsConfigPath, basePath } = options;
16
+ const roots = [...(srcPaths ?? []), ...(srcPath ? [srcPath] : [])];
16
17
  const project = createProject(tsConfigPath);
17
- project.addSourceFilesAtPaths([`${srcPath}/**/*.ts`, `${srcPath}/**/*.tsx`]);
18
+ for (const root of roots) {
19
+ project.addSourceFilesAtPaths([`${root}/**/*.ts`, `${root}/**/*.tsx`]);
20
+ }
18
21
  const usages = initializeUsagesMap(endpoints);
22
+ const relativeBase = basePath ?? process.cwd();
19
23
  for (const sourceFile of project.getSourceFiles()) {
20
- analyzeSourceFile(sourceFile, srcPath, endpoints, usages);
24
+ analyzeSourceFile(sourceFile, relativeBase, endpoints, usages);
21
25
  }
22
26
  return usages;
23
27
  }
@@ -119,13 +123,13 @@ function recordUsage(key, usage, usages, endpoints) {
119
123
  /**
120
124
  * 単一のソースファイルを解析してAPI呼び出しを検出する
121
125
  * @param sourceFile - 解析対象のソースファイル
122
- * @param srcPath - ソースディレクトリのパス
126
+ * @param basePath - 使用箇所のファイルパスを相対化する基準ディレクトリ
123
127
  * @param endpoints - OpenAPIエンドポイント一覧
124
128
  * @param usages - 使用箇所を記録するマップ(副作用で更新)
125
129
  */
126
- export function analyzeSourceFile(sourceFile, srcPath, endpoints, usages) {
130
+ export function analyzeSourceFile(sourceFile, basePath, endpoints, usages) {
127
131
  const filePath = sourceFile.getFilePath();
128
- const relativeFilePath = relative(resolve(srcPath, ".."), filePath);
132
+ const relativeFilePath = relative(resolve(basePath), filePath);
129
133
  const clientNames = findOpenApiFetchClients(sourceFile);
130
134
  sourceFile.forEachDescendant((node) => {
131
135
  const apiCall = tryExtractApiCall(node, sourceFile, clientNames);
@@ -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;AAOzD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACrC,SAAmC,EACnC,OAAuB;IAEvB,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,OAAO,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAE5C,OAAO,CAAC,qBAAqB,CAAC,CAAC,GAAG,OAAO,UAAU,EAAE,GAAG,OAAO,WAAW,CAAC,CAAC,CAAC;IAE7E,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAE9C,KAAK,MAAM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,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,10 +2,12 @@ import { Command } from "commander";
2
2
  export type SeverityLevel = "error" | "warn";
3
3
  export interface CliOptions {
4
4
  openapi?: string;
5
- src?: string;
5
+ /** 解析対象ディレクトリ。--src を複数回指定すると配列になる */
6
+ src?: string | string[];
6
7
  output?: string;
7
8
  check?: boolean;
8
- level?: SeverityLevel;
9
+ /** "error" | "warn"。不正値は起動時に検証してエラー終了する */
10
+ level?: string;
9
11
  config?: string;
10
12
  }
11
13
  /**
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;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAavC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,CAOvE"}
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;CAChB;AAMD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAiBvC;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,7 @@ 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)
12
15
  .option("--output <path>", "Output JSON file path")
13
16
  .option("--check", "Check mode (exit 1 if unused APIs exist)")
14
17
  .option("--level <level>", 'Severity level for unused APIs: "error" or "warn"')
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAapC;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,IAAI,OAAO,EAAE;SA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C;SAC7D,MAAM,CACN,iBAAiB,EACjB,mDAAmD,CACnD;SACA,MAAM,CAAC,qBAAqB,EAAE,4BAA4B,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,OAAgB,EAAE,IAAe;IAC1D,IAAI,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,EAAc,CAAC;AACnC,CAAC"}
package/dist/config.d.ts CHANGED
@@ -1,30 +1,69 @@
1
+ import { z } from "zod";
1
2
  import type { SeverityLevel } from "./cli.js";
3
+ /**
4
+ * ignoreエントリ。文字列(パターンのみ)とobject(理由付き)の両方を受け付ける
5
+ */
6
+ export type IgnoreEntry = string | {
7
+ pattern: string;
8
+ reason?: string;
9
+ };
10
+ /** 正規化済みのignoreエントリ */
11
+ export interface IgnoreRule {
12
+ pattern: string;
13
+ reason?: string;
14
+ }
2
15
  export interface Config {
3
16
  openapi?: string;
4
- src?: string;
17
+ src?: string | string[];
5
18
  output?: string;
6
19
  level?: SeverityLevel;
7
- ignore?: string[];
20
+ ignore?: IgnoreEntry[];
21
+ locations?: Record<string, string[]>;
8
22
  }
9
23
  export interface LoadConfigResult {
10
24
  success: true;
11
25
  config: Config;
26
+ warnings: string[];
12
27
  }
13
28
  export interface LoadConfigError {
14
29
  success: false;
15
30
  error: string;
16
31
  }
32
+ export declare const severityLevelSchema: z.ZodEnum<{
33
+ error: "error";
34
+ warn: "warn";
35
+ }>;
17
36
  /**
18
- * 設定ファイルを探して読み込む
37
+ * 正規表現のメタ文字をエスケープする
38
+ * @param str - エスケープ対象の文字列
39
+ * @returns リテラルとしてマッチする正規表現ソース
40
+ */
41
+ export declare function escapeRegex(str: string): string;
42
+ /**
43
+ * 設定ファイルを探して読み込み、スキーマ検証する
19
44
  * @param configPath - 明示的に指定された設定ファイルパス(省略時はデフォルトファイルを探索)
20
- * @returns 設定オブジェクトまたはエラー
45
+ * @returns 検証済みの設定オブジェクト(+警告)またはエラー
21
46
  */
22
47
  export declare function loadConfig(configPath?: string): LoadConfigResult | LoadConfigError;
48
+ /**
49
+ * ignoreエントリを正規化する(文字列/object の混在を IgnoreRule[] に揃える)
50
+ * @param entries - 設定ファイルのignoreエントリ
51
+ * @returns 正規化済みルールの配列
52
+ */
53
+ export declare function normalizeIgnoreRules(entries: IgnoreEntry[]): IgnoreRule[];
54
+ /**
55
+ * "METHOD /path" 形式のキーがパターンにマッチするか判定する
56
+ * `*` は任意の文字列にマッチし、それ以外の文字はリテラルとして扱う
57
+ * @param endpoint - "METHOD /path" 形式のエンドポイント
58
+ * @param pattern - マッチ対象のパターン
59
+ * @returns マッチした場合はtrue
60
+ */
61
+ export declare function matchEndpointPattern(endpoint: string, pattern: string): boolean;
23
62
  /**
24
63
  * エンドポイントがignoreリストにマッチするか判定
25
64
  * @param endpoint - "METHOD /path" 形式のエンドポイント
26
- * @param ignorePatterns - ignoreパターンの配列
65
+ * @param ignoreEntries - ignoreパターンの配列(文字列または理由付きobject)
27
66
  * @returns マッチした場合はtrue
28
67
  */
29
- export declare function isIgnored(endpoint: string, ignorePatterns: string[]): boolean;
68
+ export declare function isIgnored(endpoint: string, ignoreEntries: IgnoreEntry[]): boolean;
30
69
  //# sourceMappingURL=config.d.ts.map