openapi-usage 0.0.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/LICENSE +21 -0
- package/README.md +161 -0
- package/dist/analyzer.d.ts +30 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +142 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +8 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +20 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +30 -0
- package/dist/cli.js.map +1 -0
- package/dist/extractors.d.ts +9 -0
- package/dist/extractors.d.ts.map +1 -0
- package/dist/extractors.js +87 -0
- package/dist/extractors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi-parser.d.ts +21 -0
- package/dist/openapi-parser.d.ts.map +1 -0
- package/dist/openapi-parser.js +43 -0
- package/dist/openapi-parser.js.map +1 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +66 -0
- package/dist/output.js.map +1 -0
- package/dist/path-matcher.d.ts +9 -0
- package/dist/path-matcher.d.ts.map +1 -0
- package/dist/path-matcher.js +33 -0
- package/dist/path-matcher.js.map +1 -0
- package/dist/runner.d.ts +13 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +75 -0
- package/dist/runner.js.map +1 -0
- package/dist/types.d.ts +41 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# openapi-usage
|
|
2
|
+
|
|
3
|
+
OpenAPI 仕様を正として、フロントエンドの API 呼び出しを静的解析し、**呼び出し元の可視化**と**未使用 API の検知**を行うツール。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install openapi-usage
|
|
9
|
+
# or
|
|
10
|
+
pnpm add openapi-usage
|
|
11
|
+
# or
|
|
12
|
+
yarn add openapi-usage
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
グローバルインストール(CLIとして使用):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g openapi-usage
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 前提条件
|
|
22
|
+
|
|
23
|
+
- `openapi-typescript` + `openapi-fetch` を使用したAPIクライアント
|
|
24
|
+
- `createClient()` で作成されたクライアント(変数名は自動検出)
|
|
25
|
+
- 動的パス生成なし(文字列リテラルのみ)
|
|
26
|
+
|
|
27
|
+
## 検知パターン
|
|
28
|
+
|
|
29
|
+
### 検知できる
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// 文字列リテラル
|
|
33
|
+
client.GET("/users");
|
|
34
|
+
|
|
35
|
+
// createClient で作成した任意の変数名
|
|
36
|
+
const api = createClient<paths>();
|
|
37
|
+
api.GET("/users");
|
|
38
|
+
|
|
39
|
+
// 三項演算子
|
|
40
|
+
client.GET(isAdmin ? "/admins" : "/users");
|
|
41
|
+
|
|
42
|
+
// 単純な変数参照
|
|
43
|
+
const path = "/users";
|
|
44
|
+
client.GET(path);
|
|
45
|
+
|
|
46
|
+
// パスパラメータ(推奨パターン)
|
|
47
|
+
client.GET("/users/{id}", { params: { path: { id: userId } } });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 検知できない
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// テンプレートリテラル(型安全性も失われるため非推奨)
|
|
54
|
+
client.GET(`/users/${id}`);
|
|
55
|
+
|
|
56
|
+
// 関数の戻り値
|
|
57
|
+
const path = getPath();
|
|
58
|
+
client.GET(path);
|
|
59
|
+
|
|
60
|
+
// 文字列結合
|
|
61
|
+
client.GET("/users" + "/" + id);
|
|
62
|
+
|
|
63
|
+
// 動的に構築されたパス
|
|
64
|
+
const base = "/users";
|
|
65
|
+
client.GET(`${base}/${id}`);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> **Note:** 検知できないパターンは `openapi-fetch` の型安全性も失われます。
|
|
69
|
+
> パスパラメータは `params.path` で渡す方法を推奨します。
|
|
70
|
+
|
|
71
|
+
## CLI オプション
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
openapi-usage --openapi <path> --src <path> [options]
|
|
75
|
+
|
|
76
|
+
必須:
|
|
77
|
+
-o, --openapi <path> OpenAPI仕様ファイル(json)のパス
|
|
78
|
+
-s, --src <path> 解析対象ディレクトリ
|
|
79
|
+
|
|
80
|
+
オプション:
|
|
81
|
+
--output <path> JSON出力先パス
|
|
82
|
+
--check チェックモード(未使用があればexit 1)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 出力形式
|
|
86
|
+
|
|
87
|
+
### ツリー表示(--check モード)
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
GET /users
|
|
91
|
+
├─ src/pages/Users.tsx:42
|
|
92
|
+
└─ src/hooks/useUsers.ts:18
|
|
93
|
+
|
|
94
|
+
DELETE /users/{id}
|
|
95
|
+
└─ (未使用)
|
|
96
|
+
|
|
97
|
+
───────────────────────────────────
|
|
98
|
+
未使用 API: 1件
|
|
99
|
+
- DELETE /users/{id}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### JSON出力(--output モード)
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"generated_at": "2026-01-13T10:00:00Z",
|
|
107
|
+
"endpoints": [
|
|
108
|
+
{
|
|
109
|
+
"method": "GET",
|
|
110
|
+
"path": "/users",
|
|
111
|
+
"usages": [
|
|
112
|
+
{ "file": "src/pages/Users.tsx", "line": 42 }
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"summary": {
|
|
117
|
+
"total": 50,
|
|
118
|
+
"used": 49,
|
|
119
|
+
"unused": 1
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 終了コード
|
|
125
|
+
|
|
126
|
+
| コード | 意味 |
|
|
127
|
+
|--------|------|
|
|
128
|
+
| 0 | 未使用 API なし |
|
|
129
|
+
| 1 | 未使用 API あり |
|
|
130
|
+
|
|
131
|
+
## ライブラリとして使用
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import {
|
|
135
|
+
loadOpenAPISpec,
|
|
136
|
+
parseOpenAPISpec,
|
|
137
|
+
analyzeTypeScriptFiles,
|
|
138
|
+
generateJsonOutput,
|
|
139
|
+
} from "openapi-usage";
|
|
140
|
+
|
|
141
|
+
// OpenAPI仕様を読み込み
|
|
142
|
+
const specResult = loadOpenAPISpec("./openapi.json");
|
|
143
|
+
if (!specResult.success) {
|
|
144
|
+
console.error(specResult.error);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// エンドポイント一覧を抽出
|
|
149
|
+
const endpoints = parseOpenAPISpec(specResult.spec);
|
|
150
|
+
|
|
151
|
+
// TypeScriptファイルを解析
|
|
152
|
+
const usages = analyzeTypeScriptFiles(endpoints, { srcPath: "./src" });
|
|
153
|
+
|
|
154
|
+
// JSON出力を生成
|
|
155
|
+
const output = generateJsonOutput(usages);
|
|
156
|
+
console.log(JSON.stringify(output, null, 2));
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## ライセンス
|
|
160
|
+
|
|
161
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type SourceFile } from "ts-morph";
|
|
2
|
+
import { type Usage } from "./types.js";
|
|
3
|
+
export { extractStringLiterals } from "./extractors.js";
|
|
4
|
+
export { findMatchingEndpoint } from "./path-matcher.js";
|
|
5
|
+
export interface AnalyzeOptions {
|
|
6
|
+
srcPath: string;
|
|
7
|
+
tsConfigPath?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* TypeScriptファイル群を解析してAPI呼び出し箇所を検出する
|
|
11
|
+
* @param endpoints - OpenAPIから抽出したエンドポイント一覧
|
|
12
|
+
* @param options - 解析オプション(ソースパス、tsconfig等)
|
|
13
|
+
* @returns エンドポイントごとの使用箇所マップ
|
|
14
|
+
*/
|
|
15
|
+
export declare function analyzeTypeScriptFiles(endpoints: Map<string, Set<string>>, options: AnalyzeOptions): Map<string, Usage[]>;
|
|
16
|
+
/**
|
|
17
|
+
* ソースファイルからopenapi-fetchのクライアント変数名を検出する
|
|
18
|
+
* @param sourceFile - 解析対象のソースファイル
|
|
19
|
+
* @returns クライアント変数名のSet(例: "client", "api")
|
|
20
|
+
*/
|
|
21
|
+
export declare function findOpenApiFetchClients(sourceFile: SourceFile): Set<string>;
|
|
22
|
+
/**
|
|
23
|
+
* 単一のソースファイルを解析してAPI呼び出しを検出する
|
|
24
|
+
* @param sourceFile - 解析対象のソースファイル
|
|
25
|
+
* @param srcPath - ソースディレクトリのパス
|
|
26
|
+
* @param endpoints - OpenAPIエンドポイント一覧
|
|
27
|
+
* @param usages - 使用箇所を記録するマップ(副作用で更新)
|
|
28
|
+
*/
|
|
29
|
+
export declare function analyzeSourceFile(sourceFile: SourceFile, srcPath: string, endpoints: Map<string, Set<string>>, usages: Map<string, Usage[]>): void;
|
|
30
|
+
//# sourceMappingURL=analyzer.d.ts.map
|
|
@@ -0,0 +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,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;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,CAatB;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,OAAO,EAAE,MAAM,EACf,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
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { relative, resolve } from "node:path";
|
|
2
|
+
import { Node, Project } from "ts-morph";
|
|
3
|
+
import { extractStringLiterals } from "./extractors.js";
|
|
4
|
+
import { findMatchingEndpoint } from "./path-matcher.js";
|
|
5
|
+
import { HTTP_METHODS } from "./types.js";
|
|
6
|
+
export { extractStringLiterals } from "./extractors.js";
|
|
7
|
+
export { findMatchingEndpoint } from "./path-matcher.js";
|
|
8
|
+
/**
|
|
9
|
+
* TypeScriptファイル群を解析してAPI呼び出し箇所を検出する
|
|
10
|
+
* @param endpoints - OpenAPIから抽出したエンドポイント一覧
|
|
11
|
+
* @param options - 解析オプション(ソースパス、tsconfig等)
|
|
12
|
+
* @returns エンドポイントごとの使用箇所マップ
|
|
13
|
+
*/
|
|
14
|
+
export function analyzeTypeScriptFiles(endpoints, options) {
|
|
15
|
+
const { srcPath, tsConfigPath } = options;
|
|
16
|
+
const project = createProject(tsConfigPath);
|
|
17
|
+
project.addSourceFilesAtPaths([`${srcPath}/**/*.ts`, `${srcPath}/**/*.tsx`]);
|
|
18
|
+
const usages = initializeUsagesMap(endpoints);
|
|
19
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
20
|
+
analyzeSourceFile(sourceFile, srcPath, endpoints, usages);
|
|
21
|
+
}
|
|
22
|
+
return usages;
|
|
23
|
+
}
|
|
24
|
+
function createProject(tsConfigPath) {
|
|
25
|
+
const options = {
|
|
26
|
+
skipAddingFilesFromTsConfig: true,
|
|
27
|
+
};
|
|
28
|
+
if (tsConfigPath) {
|
|
29
|
+
options.tsConfigFilePath = tsConfigPath;
|
|
30
|
+
}
|
|
31
|
+
return new Project(options);
|
|
32
|
+
}
|
|
33
|
+
function initializeUsagesMap(endpoints) {
|
|
34
|
+
const usages = new Map();
|
|
35
|
+
for (const key of endpoints.keys()) {
|
|
36
|
+
usages.set(key, []);
|
|
37
|
+
}
|
|
38
|
+
return usages;
|
|
39
|
+
}
|
|
40
|
+
function isOpenApiFetchImported(sourceFile) {
|
|
41
|
+
for (const importDecl of sourceFile.getImportDeclarations()) {
|
|
42
|
+
if (importDecl.getModuleSpecifierValue() !== "openapi-fetch")
|
|
43
|
+
continue;
|
|
44
|
+
const namedImports = importDecl.getNamedImports();
|
|
45
|
+
for (const namedImport of namedImports) {
|
|
46
|
+
if (namedImport.getName() === "createClient") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
51
|
+
if (defaultImport?.getText() === "createClient") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* ソースファイルからopenapi-fetchのクライアント変数名を検出する
|
|
59
|
+
* @param sourceFile - 解析対象のソースファイル
|
|
60
|
+
* @returns クライアント変数名のSet(例: "client", "api")
|
|
61
|
+
*/
|
|
62
|
+
export function findOpenApiFetchClients(sourceFile) {
|
|
63
|
+
const clientNames = new Set();
|
|
64
|
+
if (!isOpenApiFetchImported(sourceFile)) {
|
|
65
|
+
clientNames.add("client");
|
|
66
|
+
return clientNames;
|
|
67
|
+
}
|
|
68
|
+
sourceFile.forEachDescendant((node) => {
|
|
69
|
+
if (!Node.isVariableDeclaration(node))
|
|
70
|
+
return;
|
|
71
|
+
const initializer = node.getInitializer();
|
|
72
|
+
if (!initializer || !Node.isCallExpression(initializer))
|
|
73
|
+
return;
|
|
74
|
+
const callExpr = initializer.getExpression();
|
|
75
|
+
if (Node.isIdentifier(callExpr) && callExpr.getText() === "createClient") {
|
|
76
|
+
clientNames.add(node.getName());
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (clientNames.size === 0) {
|
|
80
|
+
clientNames.add("client");
|
|
81
|
+
}
|
|
82
|
+
return clientNames;
|
|
83
|
+
}
|
|
84
|
+
function tryExtractApiCall(node, sourceFile, clientNames) {
|
|
85
|
+
if (!Node.isCallExpression(node))
|
|
86
|
+
return null;
|
|
87
|
+
const callExpr = node;
|
|
88
|
+
const expression = callExpr.getExpression();
|
|
89
|
+
if (!Node.isPropertyAccessExpression(expression))
|
|
90
|
+
return null;
|
|
91
|
+
const methodName = expression.getName();
|
|
92
|
+
const objectExpr = expression.getExpression();
|
|
93
|
+
const isValidApiCall = Node.isIdentifier(objectExpr) &&
|
|
94
|
+
clientNames.has(objectExpr.getText()) &&
|
|
95
|
+
HTTP_METHODS.includes(methodName);
|
|
96
|
+
if (!isValidApiCall)
|
|
97
|
+
return null;
|
|
98
|
+
const args = callExpr.getArguments();
|
|
99
|
+
if (args.length === 0)
|
|
100
|
+
return null;
|
|
101
|
+
return {
|
|
102
|
+
methodName,
|
|
103
|
+
pathArg: args[0],
|
|
104
|
+
line: sourceFile.getLineAndColumnAtPos(node.getStart()).line,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function recordUsage(key, usage, usages, endpoints) {
|
|
108
|
+
const existingUsages = usages.get(key);
|
|
109
|
+
if (existingUsages) {
|
|
110
|
+
existingUsages.push(usage);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const matchedKey = findMatchingEndpoint(key, endpoints);
|
|
114
|
+
if (matchedKey) {
|
|
115
|
+
usages.get(matchedKey)?.push(usage);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 単一のソースファイルを解析してAPI呼び出しを検出する
|
|
121
|
+
* @param sourceFile - 解析対象のソースファイル
|
|
122
|
+
* @param srcPath - ソースディレクトリのパス
|
|
123
|
+
* @param endpoints - OpenAPIエンドポイント一覧
|
|
124
|
+
* @param usages - 使用箇所を記録するマップ(副作用で更新)
|
|
125
|
+
*/
|
|
126
|
+
export function analyzeSourceFile(sourceFile, srcPath, endpoints, usages) {
|
|
127
|
+
const filePath = sourceFile.getFilePath();
|
|
128
|
+
const relativeFilePath = relative(resolve(srcPath, ".."), filePath);
|
|
129
|
+
const clientNames = findOpenApiFetchClients(sourceFile);
|
|
130
|
+
sourceFile.forEachDescendant((node) => {
|
|
131
|
+
const apiCall = tryExtractApiCall(node, sourceFile, clientNames);
|
|
132
|
+
if (!apiCall)
|
|
133
|
+
return;
|
|
134
|
+
const pathValues = extractStringLiterals(apiCall.pathArg);
|
|
135
|
+
const usage = { file: relativeFilePath, line: apiCall.line };
|
|
136
|
+
for (const pathValue of pathValues) {
|
|
137
|
+
const key = `${apiCall.methodName} ${pathValue}`;
|
|
138
|
+
recordUsage(key, usage, usages, endpoints);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=analyzer.js.map
|
|
@@ -0,0 +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,UAA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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createProgram, parseArgs } from "./cli.js";
|
|
3
|
+
import { run } from "./runner.js";
|
|
4
|
+
const program = createProgram();
|
|
5
|
+
const options = parseArgs(program);
|
|
6
|
+
const result = run(options);
|
|
7
|
+
process.exit(result.exitCode);
|
|
8
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;AAChC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AACnC,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;AAE5B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
export interface CliOptions {
|
|
3
|
+
openapi: string;
|
|
4
|
+
src: string;
|
|
5
|
+
output?: string;
|
|
6
|
+
check?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* CLIプログラムを作成する
|
|
10
|
+
* @returns Commanderプログラムインスタンス
|
|
11
|
+
*/
|
|
12
|
+
export declare function createProgram(): Command;
|
|
13
|
+
/**
|
|
14
|
+
* コマンドライン引数をパースしてオプションを取得する
|
|
15
|
+
* @param program - Commanderプログラムインスタンス
|
|
16
|
+
* @param args - 引数配列(テスト用、省略時はprocess.argvを使用)
|
|
17
|
+
* @returns パースされたCLIオプション
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseArgs(program: Command, args?: string[]): CliOptions;
|
|
20
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +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,WAAW,UAAU;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAQvC;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,CAOvE"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* CLIプログラムを作成する
|
|
4
|
+
* @returns Commanderプログラムインスタンス
|
|
5
|
+
*/
|
|
6
|
+
export function createProgram() {
|
|
7
|
+
return new Command()
|
|
8
|
+
.name("openapi-usage")
|
|
9
|
+
.description("Analyze API usage based on OpenAPI spec")
|
|
10
|
+
.requiredOption("-o, --openapi <path>", "Path to OpenAPI spec file")
|
|
11
|
+
.requiredOption("-s, --src <path>", "Path to source directory")
|
|
12
|
+
.option("--output <path>", "Output JSON file path")
|
|
13
|
+
.option("--check", "Check mode (exit 1 if unused APIs exist)");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* コマンドライン引数をパースしてオプションを取得する
|
|
17
|
+
* @param program - Commanderプログラムインスタンス
|
|
18
|
+
* @param args - 引数配列(テスト用、省略時はprocess.argvを使用)
|
|
19
|
+
* @returns パースされたCLIオプション
|
|
20
|
+
*/
|
|
21
|
+
export function parseArgs(program, args) {
|
|
22
|
+
if (args) {
|
|
23
|
+
program.parse(args, { from: "user" });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
program.parse();
|
|
27
|
+
}
|
|
28
|
+
return program.opts();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,IAAI,OAAO,EAAE;SAClB,IAAI,CAAC,eAAe,CAAC;SACrB,WAAW,CAAC,yCAAyC,CAAC;SACtD,cAAc,CAAC,sBAAsB,EAAE,2BAA2B,CAAC;SACnE,cAAc,CAAC,kBAAkB,EAAE,0BAA0B,CAAC;SAC9D,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;SAClD,MAAM,CAAC,SAAS,EAAE,0CAA0C,CAAC,CAAC;AACjE,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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Node } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* ASTノードから文字列リテラルを抽出する
|
|
4
|
+
* テンプレートリテラル、三項演算子、変数参照などに対応
|
|
5
|
+
* @param node - 解析対象のASTノード
|
|
6
|
+
* @returns 抽出された文字列リテラルの配列
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractStringLiterals(node: Node): string[];
|
|
9
|
+
//# sourceMappingURL=extractors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractors.d.ts","sourceRoot":"","sources":["../src/extractors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAgFhC;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,CAQ1D"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Node } from "ts-morph";
|
|
2
|
+
function extractFromStringLiteral(node) {
|
|
3
|
+
if (!Node.isStringLiteral(node))
|
|
4
|
+
return null;
|
|
5
|
+
return [node.getLiteralValue()];
|
|
6
|
+
}
|
|
7
|
+
function extractFromTemplateLiteral(node) {
|
|
8
|
+
if (!Node.isNoSubstitutionTemplateLiteral(node))
|
|
9
|
+
return null;
|
|
10
|
+
return [node.getLiteralValue()];
|
|
11
|
+
}
|
|
12
|
+
function extractFromTemplateExpression(node) {
|
|
13
|
+
if (!Node.isTemplateExpression(node))
|
|
14
|
+
return null;
|
|
15
|
+
const head = node.getHead().getText().slice(1, -2);
|
|
16
|
+
const spans = node.getTemplateSpans();
|
|
17
|
+
let pattern = head;
|
|
18
|
+
for (const span of spans) {
|
|
19
|
+
const expr = span.getExpression();
|
|
20
|
+
const varName = Node.isIdentifier(expr) ? expr.getText() : "param";
|
|
21
|
+
pattern += `{${varName}}`;
|
|
22
|
+
const literal = span.getLiteral();
|
|
23
|
+
const literalText = literal.getText();
|
|
24
|
+
const cleanText = literalText.startsWith("}")
|
|
25
|
+
? literalText.slice(1, literalText.endsWith("`") ? -1 : -2)
|
|
26
|
+
: literalText;
|
|
27
|
+
pattern += cleanText;
|
|
28
|
+
}
|
|
29
|
+
return [pattern];
|
|
30
|
+
}
|
|
31
|
+
function extractFromConditionalExpression(node) {
|
|
32
|
+
if (!Node.isConditionalExpression(node))
|
|
33
|
+
return null;
|
|
34
|
+
return [
|
|
35
|
+
...extractStringLiterals(node.getWhenTrue()),
|
|
36
|
+
...extractStringLiterals(node.getWhenFalse()),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
function extractFromIdentifier(node) {
|
|
40
|
+
if (!Node.isIdentifier(node))
|
|
41
|
+
return null;
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const def of node.getDefinitionNodes()) {
|
|
44
|
+
if (Node.isVariableDeclaration(def) || Node.isParameterDeclaration(def)) {
|
|
45
|
+
const initializer = def.getInitializer();
|
|
46
|
+
if (initializer) {
|
|
47
|
+
results.push(...extractStringLiterals(initializer));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
function extractFromParenthesizedExpression(node) {
|
|
54
|
+
if (!Node.isParenthesizedExpression(node))
|
|
55
|
+
return null;
|
|
56
|
+
return extractStringLiterals(node.getExpression());
|
|
57
|
+
}
|
|
58
|
+
function extractFromAsExpression(node) {
|
|
59
|
+
if (!Node.isAsExpression(node))
|
|
60
|
+
return null;
|
|
61
|
+
return extractStringLiterals(node.getExpression());
|
|
62
|
+
}
|
|
63
|
+
const stringLiteralExtractors = [
|
|
64
|
+
extractFromStringLiteral,
|
|
65
|
+
extractFromTemplateLiteral,
|
|
66
|
+
extractFromTemplateExpression,
|
|
67
|
+
extractFromConditionalExpression,
|
|
68
|
+
extractFromIdentifier,
|
|
69
|
+
extractFromParenthesizedExpression,
|
|
70
|
+
extractFromAsExpression,
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* ASTノードから文字列リテラルを抽出する
|
|
74
|
+
* テンプレートリテラル、三項演算子、変数参照などに対応
|
|
75
|
+
* @param node - 解析対象のASTノード
|
|
76
|
+
* @returns 抽出された文字列リテラルの配列
|
|
77
|
+
*/
|
|
78
|
+
export function extractStringLiterals(node) {
|
|
79
|
+
for (const extractor of stringLiteralExtractors) {
|
|
80
|
+
const result = extractor(node);
|
|
81
|
+
if (result !== null) {
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=extractors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractors.js","sourceRoot":"","sources":["../src/extractors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,SAAS,wBAAwB,CAAC,IAAU;IAC3C,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,0BAA0B,CAAC,IAAU;IAC7C,IAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,6BAA6B,CAAC,IAAU;IAChD,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAElD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAEtC,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,OAAO,IAAI,IAAI,OAAO,GAAG,CAAC;QAE1B,MAAM,OA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C;AAChB,CAAC;AAED,SAAS,kCAAkC,CAAC,IAAU;IACrD,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,qBAAqB,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAU;IAC1C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,qBAAqB,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,uBAAuB,GAAsB;IAClD,wBAAwB;IACxB,0BAA0B;IAC1B,6BAA6B;IAC7B,gCAAgC;IAChC,qBAAqB;IACrB,kCAAkC;IAClC,uBAAuB;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAU;IAC/C,KAAK,MAAM,SAAS,IAAI,uBAAuB,EAAE,CAAC;QACjD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { type AnalyzeOptions, analyzeSourceFile, analyzeTypeScriptFiles, extractStringLiterals, findMatchingEndpoint, findOpenApiFetchClients, } from "./analyzer.js";
|
|
2
|
+
export { type CliOptions, createProgram, parseArgs } from "./cli.js";
|
|
3
|
+
export { type LoadResult, loadOpenAPISpec, parseOpenAPISpec, } from "./openapi-parser.js";
|
|
4
|
+
export { formatSummary, formatTree, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
5
|
+
export { type RunResult, run } from "./runner.js";
|
|
6
|
+
export type { ApiDependencies, Endpoint, HttpMethod, OpenAPIOperation, OpenAPIPathItem, OpenAPISpec, Usage, } from "./types.js";
|
|
7
|
+
export { HTTP_METHODS } from "./types.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,cAAc,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErE,OAAO,EACN,KAAK,UAAU,EACf,eAAe,EACf,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,KAAK,GACL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ライブラリエクスポート
|
|
2
|
+
// Analyzer
|
|
3
|
+
export { analyzeSourceFile, analyzeTypeScriptFiles, extractStringLiterals, findMatchingEndpoint, findOpenApiFetchClients, } from "./analyzer.js";
|
|
4
|
+
// CLI
|
|
5
|
+
export { createProgram, parseArgs } from "./cli.js";
|
|
6
|
+
// OpenAPI Parser
|
|
7
|
+
export { loadOpenAPISpec, parseOpenAPISpec, } from "./openapi-parser.js";
|
|
8
|
+
// Output
|
|
9
|
+
export { formatSummary, formatTree, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
10
|
+
// Runner
|
|
11
|
+
export { run } from "./runner.js";
|
|
12
|
+
export { HTTP_METHODS } from "./types.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,WAAW;AACX,OAAO,EAEN,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAEvB,MAAM;AACN,OAAO,EAAmB,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,iBAAiB;AACjB,OAAO,EAEN,eAAe,EACf,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAC7B,SAAS;AACT,OAAO,EACN,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,aAAa,CAAC;AACrB,SAAS;AACT,OAAO,EAAkB,GAAG,EAAE,MAAM,aAAa,CAAC;AAalD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type OpenAPISpec } from "./types.js";
|
|
2
|
+
export type LoadResult = {
|
|
3
|
+
success: true;
|
|
4
|
+
spec: OpenAPISpec;
|
|
5
|
+
} | {
|
|
6
|
+
success: false;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* OpenAPI仕様ファイルを読み込んでパースする
|
|
11
|
+
* @param filePath - OpenAPI JSONファイルのパス
|
|
12
|
+
* @returns 成功時はspec、失敗時はエラーメッセージを含むResult型
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadOpenAPISpec(filePath: string): LoadResult;
|
|
15
|
+
/**
|
|
16
|
+
* OpenAPI仕様からエンドポイント一覧を抽出する
|
|
17
|
+
* @param spec - パース済みのOpenAPI仕様オブジェクト
|
|
18
|
+
* @returns エンドポイントキー("GET /users"形式)のMap
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseOpenAPISpec(spec: OpenAPISpec): Map<string, Set<string>>;
|
|
21
|
+
//# sourceMappingURL=openapi-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-parser.d.ts","sourceRoot":"","sources":["../src/openapi-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,MAAM,UAAU,GACnB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACpC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAe5D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAc5E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { HTTP_METHODS } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* OpenAPI仕様ファイルを読み込んでパースする
|
|
5
|
+
* @param filePath - OpenAPI JSONファイルのパス
|
|
6
|
+
* @returns 成功時はspec、失敗時はエラーメッセージを含むResult型
|
|
7
|
+
*/
|
|
8
|
+
export function loadOpenAPISpec(filePath) {
|
|
9
|
+
try {
|
|
10
|
+
const content = readFileSync(filePath, "utf-8");
|
|
11
|
+
const spec = JSON.parse(content);
|
|
12
|
+
return { success: true, spec };
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error instanceof SyntaxError) {
|
|
16
|
+
return {
|
|
17
|
+
success: false,
|
|
18
|
+
error: `Invalid JSON in OpenAPI spec: ${error.message}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
return { success: false, error: `Failed to read OpenAPI spec: ${message}` };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* OpenAPI仕様からエンドポイント一覧を抽出する
|
|
27
|
+
* @param spec - パース済みのOpenAPI仕様オブジェクト
|
|
28
|
+
* @returns エンドポイントキー("GET /users"形式)のMap
|
|
29
|
+
*/
|
|
30
|
+
export function parseOpenAPISpec(spec) {
|
|
31
|
+
const endpoints = new Map();
|
|
32
|
+
for (const [path, methods] of Object.entries(spec.paths)) {
|
|
33
|
+
for (const method of Object.keys(methods)) {
|
|
34
|
+
const upperMethod = method.toUpperCase();
|
|
35
|
+
if (HTTP_METHODS.includes(upperMethod)) {
|
|
36
|
+
const key = `${upperMethod} ${path}`;
|
|
37
|
+
endpoints.set(key, new Set());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return endpoints;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=openapi-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-parser.js","sourceRoot":"","sources":["../src/openapi-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAqC,MAAM,YAAY,CAAC;AAM7E;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC/C,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAgB,CAAC;QAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YAClC,OAAO;gBACN,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,iCAAiC,KAAK,CAAC,OAAO,EAAE;aACvD,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,gCAAgC,OAAO,EAAE,EAAE,CAAC;IAC7E,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEjD,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YACzC,IAAI,YAAY,CAAC,QAAQ,CAAC,WAAyB,CAAC,EAAE,CAAC;gBACtD,MAAM,GAAG,GAAG,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC;gBACrC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YAC/B,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ApiDependencies, Usage } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* API使用状況をツリー形式の文字列配列に変換する
|
|
4
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
5
|
+
* @returns ツリー形式の出力行配列
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatTree: (usages: Map<string, Usage[]>) => string[];
|
|
8
|
+
/**
|
|
9
|
+
* 未使用のエンドポイント一覧を取得する
|
|
10
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
11
|
+
* @returns 未使用エンドポイントキーの配列
|
|
12
|
+
*/
|
|
13
|
+
export declare const getUnusedEndpoints: (usages: Map<string, Usage[]>) => string[];
|
|
14
|
+
/**
|
|
15
|
+
* 未使用API数のサマリーを文字列配列に変換する
|
|
16
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
17
|
+
* @returns サマリー出力行配列
|
|
18
|
+
*/
|
|
19
|
+
export declare const formatSummary: (usages: Map<string, Usage[]>) => string[];
|
|
20
|
+
/**
|
|
21
|
+
* API使用状況をJSON出力用のオブジェクトに変換する
|
|
22
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
23
|
+
* @param generatedAt - 生成日時(省略時は現在時刻)
|
|
24
|
+
* @returns JSON出力用のApiDependenciesオブジェクト
|
|
25
|
+
*/
|
|
26
|
+
export declare const generateJsonOutput: (usages: Map<string, Usage[]>, generatedAt?: Date) => ApiDependencies;
|
|
27
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAY,KAAK,EAAE,MAAM,YAAY,CAAC;AAkBnE;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAG9D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAGlD,CAAC;AAEvB;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAalE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC9B,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAC5B,cAAa,IAAiB,KAC5B,eAmBF,CAAC"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const sortByKey = (entries) => entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
2
|
+
const formatUsageLines = (key, usages) => {
|
|
3
|
+
if (usages.length === 0) {
|
|
4
|
+
return [key, "└─ (未使用)", ""];
|
|
5
|
+
}
|
|
6
|
+
const usageLines = usages.map((usage, index) => {
|
|
7
|
+
const prefix = index === usages.length - 1 ? "└─" : "├─";
|
|
8
|
+
return `${prefix} ${usage.file}:${usage.line}`;
|
|
9
|
+
});
|
|
10
|
+
return [key, ...usageLines, ""];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* API使用状況をツリー形式の文字列配列に変換する
|
|
14
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
15
|
+
* @returns ツリー形式の出力行配列
|
|
16
|
+
*/
|
|
17
|
+
export const formatTree = (usages) => sortByKey([...usages.entries()]).flatMap(([key, list]) => formatUsageLines(key, list));
|
|
18
|
+
/**
|
|
19
|
+
* 未使用のエンドポイント一覧を取得する
|
|
20
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
21
|
+
* @returns 未使用エンドポイントキーの配列
|
|
22
|
+
*/
|
|
23
|
+
export const getUnusedEndpoints = (usages) => [...usages.entries()]
|
|
24
|
+
.filter(([, list]) => list.length === 0)
|
|
25
|
+
.map(([key]) => key);
|
|
26
|
+
/**
|
|
27
|
+
* 未使用API数のサマリーを文字列配列に変換する
|
|
28
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
29
|
+
* @returns サマリー出力行配列
|
|
30
|
+
*/
|
|
31
|
+
export const formatSummary = (usages) => {
|
|
32
|
+
const unused = getUnusedEndpoints(usages);
|
|
33
|
+
const separator = "─".repeat(35);
|
|
34
|
+
if (unused.length === 0) {
|
|
35
|
+
return [separator, "未使用 API: 0件"];
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
separator,
|
|
39
|
+
`未使用 API: ${unused.length}件`,
|
|
40
|
+
...unused.map((endpoint) => ` - ${endpoint}`),
|
|
41
|
+
];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* API使用状況をJSON出力用のオブジェクトに変換する
|
|
45
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
46
|
+
* @param generatedAt - 生成日時(省略時は現在時刻)
|
|
47
|
+
* @returns JSON出力用のApiDependenciesオブジェクト
|
|
48
|
+
*/
|
|
49
|
+
export const generateJsonOutput = (usages, generatedAt = new Date()) => {
|
|
50
|
+
const entries = sortByKey([...usages.entries()]);
|
|
51
|
+
const endpoints = entries.map(([key, usageList]) => {
|
|
52
|
+
const [method, path] = key.split(" ", 2);
|
|
53
|
+
return { method, path, usages: usageList };
|
|
54
|
+
});
|
|
55
|
+
const used = entries.filter(([, list]) => list.length > 0).length;
|
|
56
|
+
return {
|
|
57
|
+
generated_at: generatedAt.toISOString(),
|
|
58
|
+
endpoints,
|
|
59
|
+
summary: {
|
|
60
|
+
total: endpoints.length,
|
|
61
|
+
used,
|
|
62
|
+
unused: endpoints.length - used,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,CAAI,OAAsB,EAAiB,EAAE,CAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAElD,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,MAAe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,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 実際のAPIパスにマッチするOpenAPIエンドポイントを検索する
|
|
3
|
+
* パスパラメータ({id}等)を考慮したパターンマッチングを行う
|
|
4
|
+
* @param key - 検索対象のAPIキー(例: "GET /users/123")
|
|
5
|
+
* @param endpoints - OpenAPIエンドポイント一覧
|
|
6
|
+
* @returns マッチしたエンドポイントキー、なければnull
|
|
7
|
+
*/
|
|
8
|
+
export declare function findMatchingEndpoint(key: string, endpoints: Map<string, Set<string>>): string | null;
|
|
9
|
+
//# sourceMappingURL=path-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-matcher.d.ts","sourceRoot":"","sources":["../src/path-matcher.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GACjC,MAAM,GAAG,IAAI,CAgBf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function escapeRegex(str) {
|
|
2
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
}
|
|
4
|
+
function parseEndpointKey(key) {
|
|
5
|
+
const [method, path] = key.split(" ", 2);
|
|
6
|
+
return { method, path };
|
|
7
|
+
}
|
|
8
|
+
function createPathRegex(endpointPath) {
|
|
9
|
+
const escapedPath = escapeRegex(endpointPath);
|
|
10
|
+
const regexPattern = escapedPath.replace(/\\\{[^}]+\\\}/g, "[^/]+");
|
|
11
|
+
return new RegExp(`^${regexPattern}$`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 実際のAPIパスにマッチするOpenAPIエンドポイントを検索する
|
|
15
|
+
* パスパラメータ({id}等)を考慮したパターンマッチングを行う
|
|
16
|
+
* @param key - 検索対象のAPIキー(例: "GET /users/123")
|
|
17
|
+
* @param endpoints - OpenAPIエンドポイント一覧
|
|
18
|
+
* @returns マッチしたエンドポイントキー、なければnull
|
|
19
|
+
*/
|
|
20
|
+
export function findMatchingEndpoint(key, endpoints) {
|
|
21
|
+
const { method, path } = parseEndpointKey(key);
|
|
22
|
+
for (const endpointKey of endpoints.keys()) {
|
|
23
|
+
const { method: endpointMethod, path: endpointPath } = parseEndpointKey(endpointKey);
|
|
24
|
+
if (method !== endpointMethod)
|
|
25
|
+
continue;
|
|
26
|
+
const regex = createPathRegex(endpointPath);
|
|
27
|
+
if (regex.test(path)) {
|
|
28
|
+
return endpointKey;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=path-matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-matcher.js","sourceRoot":"","sources":["../src/path-matcher.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW;IACpC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,SAAS,eAAe,CAAC,YAAoB;IAC5C,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACpE,OAAO,IAAI,MAAM,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CACnC,GAAW,EACX,SAAmC;IAEnC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAE/C,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,GACnD,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAE/B,IAAI,MAAM,KAAK,cAAc;YAAE,SAAS;QAExC,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,OAAO,WAAW,CAAC;QACpB,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CliOptions } from "./cli.js";
|
|
2
|
+
export interface RunResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
exitCode: number;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* API使用状況解析を実行する
|
|
9
|
+
* @param options - CLIオプション(OpenAPIパス、ソースパス等)
|
|
10
|
+
* @returns 実行結果(成功/失敗、終了コード、エラーメッセージ)
|
|
11
|
+
*/
|
|
12
|
+
export declare function run(options: CliOptions): RunResult;
|
|
13
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAU3C,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAgDD;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAsClD"}
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { analyzeTypeScriptFiles } from "./analyzer.js";
|
|
4
|
+
import { loadOpenAPISpec, parseOpenAPISpec } from "./openapi-parser.js";
|
|
5
|
+
import { formatSummary, formatTree, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
6
|
+
function resolvePaths(options) {
|
|
7
|
+
return {
|
|
8
|
+
openapiPath: resolve(process.cwd(), options.openapi),
|
|
9
|
+
srcPath: resolve(process.cwd(), options.src),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function validatePaths(openapiPath, srcPath) {
|
|
13
|
+
if (!existsSync(openapiPath)) {
|
|
14
|
+
return `OpenAPI spec not found: ${openapiPath}`;
|
|
15
|
+
}
|
|
16
|
+
if (!existsSync(srcPath)) {
|
|
17
|
+
return `Source directory not found: ${srcPath}`;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function writeJsonOutput(outputPath, usages) {
|
|
22
|
+
const resolvedPath = resolve(process.cwd(), outputPath);
|
|
23
|
+
const outputDir = dirname(resolvedPath);
|
|
24
|
+
if (!existsSync(outputDir)) {
|
|
25
|
+
mkdirSync(outputDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
const jsonOutput = generateJsonOutput(usages);
|
|
28
|
+
writeFileSync(resolvedPath, JSON.stringify(jsonOutput, null, 2));
|
|
29
|
+
console.log(`Output written to: ${resolvedPath}`);
|
|
30
|
+
}
|
|
31
|
+
function printUsageReport(usages) {
|
|
32
|
+
console.log();
|
|
33
|
+
for (const line of formatTree(usages)) {
|
|
34
|
+
console.log(line);
|
|
35
|
+
}
|
|
36
|
+
for (const line of formatSummary(usages)) {
|
|
37
|
+
console.log(line);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* API使用状況解析を実行する
|
|
42
|
+
* @param options - CLIオプション(OpenAPIパス、ソースパス等)
|
|
43
|
+
* @returns 実行結果(成功/失敗、終了コード、エラーメッセージ)
|
|
44
|
+
*/
|
|
45
|
+
export function run(options) {
|
|
46
|
+
const { openapiPath, srcPath } = resolvePaths(options);
|
|
47
|
+
const validationError = validatePaths(openapiPath, srcPath);
|
|
48
|
+
if (validationError) {
|
|
49
|
+
console.error(`Error: ${validationError}`);
|
|
50
|
+
return { success: false, exitCode: 1, error: validationError };
|
|
51
|
+
}
|
|
52
|
+
console.log(`Parsing OpenAPI spec: ${openapiPath}`);
|
|
53
|
+
const specResult = loadOpenAPISpec(openapiPath);
|
|
54
|
+
if (!specResult.success) {
|
|
55
|
+
console.error(`Error: ${specResult.error}`);
|
|
56
|
+
return { success: false, exitCode: 1, error: specResult.error };
|
|
57
|
+
}
|
|
58
|
+
const endpoints = parseOpenAPISpec(specResult.spec);
|
|
59
|
+
console.log(`Found ${endpoints.size} endpoints`);
|
|
60
|
+
console.log(`Analyzing source files: ${srcPath}`);
|
|
61
|
+
const usages = analyzeTypeScriptFiles(endpoints, { srcPath });
|
|
62
|
+
if (options.output) {
|
|
63
|
+
writeJsonOutput(options.output, usages);
|
|
64
|
+
}
|
|
65
|
+
if (options.check) {
|
|
66
|
+
printUsageReport(usages);
|
|
67
|
+
const exitCode = getUnusedEndpoints(usages).length > 0 ? 1 : 0;
|
|
68
|
+
return { success: true, exitCode };
|
|
69
|
+
}
|
|
70
|
+
if (!options.output && !options.check) {
|
|
71
|
+
printUsageReport(usages);
|
|
72
|
+
}
|
|
73
|
+
return { success: true, exitCode: 0 };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC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AC,UAAU,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,SAAS,SAAS,CAAC,IAAI,YAAY,CAAC,CAAC;IAEjD,OAAO,CAAC,GAAG,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAE9D,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACnB,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface OpenAPIOperation {
|
|
2
|
+
summary?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
operationId?: string;
|
|
5
|
+
parameters?: unknown[];
|
|
6
|
+
requestBody?: unknown;
|
|
7
|
+
responses?: Record<string, unknown>;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenAPIPathItem {
|
|
11
|
+
get?: OpenAPIOperation;
|
|
12
|
+
post?: OpenAPIOperation;
|
|
13
|
+
put?: OpenAPIOperation;
|
|
14
|
+
delete?: OpenAPIOperation;
|
|
15
|
+
patch?: OpenAPIOperation;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenAPISpec {
|
|
19
|
+
paths: Record<string, OpenAPIPathItem>;
|
|
20
|
+
}
|
|
21
|
+
export interface Usage {
|
|
22
|
+
file: string;
|
|
23
|
+
line: number;
|
|
24
|
+
}
|
|
25
|
+
export interface Endpoint {
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
usages: Usage[];
|
|
29
|
+
}
|
|
30
|
+
export interface ApiDependencies {
|
|
31
|
+
generated_at: string;
|
|
32
|
+
endpoints: Endpoint[];
|
|
33
|
+
summary: {
|
|
34
|
+
total: number;
|
|
35
|
+
used: number;
|
|
36
|
+
unused: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
40
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,EAAE,gBAAgB,CAAC;IACvB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,GAAG,CAAC,EAAE,gBAAgB,CAAC;IACvB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KACf,CAAC;CACF;AAED,eAAO,MAAM,YAAY,oDAAqD,CAAC;AAC/E,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4CA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openapi-usage",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "OpenAPI仕様を正としてAPIの使用状況を静的解析し、未使用APIを検知するツール",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openapi",
|
|
7
|
+
"api",
|
|
8
|
+
"analyzer",
|
|
9
|
+
"static-analysis",
|
|
10
|
+
"typescript",
|
|
11
|
+
"openapi-fetch",
|
|
12
|
+
"unused-api",
|
|
13
|
+
"cli"
|
|
14
|
+
],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/Glider2355/openapi-usage.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Glider2355/openapi-usage/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/Glider2355/openapi-usage#readme",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"bin": {
|
|
29
|
+
"openapi-usage": "dist/bin.js"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.build.json && chmod +x dist/bin.js",
|
|
47
|
+
"clean": "rm -rf dist",
|
|
48
|
+
"prebuild": "pnpm clean",
|
|
49
|
+
"prepublishOnly": "pnpm build",
|
|
50
|
+
"test": "vitest",
|
|
51
|
+
"test:run": "vitest run",
|
|
52
|
+
"lint": "biome check .",
|
|
53
|
+
"format": "biome check --write .",
|
|
54
|
+
"typecheck": "tsc --noEmit"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"commander": "^13.1.0",
|
|
58
|
+
"ts-morph": "^25.0.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@biomejs/biome": "^2.3.11",
|
|
62
|
+
"@changesets/cli": "^2.27.0",
|
|
63
|
+
"@types/node": "^22.15.29",
|
|
64
|
+
"lefthook": "^2.0.15",
|
|
65
|
+
"tsx": "^4.19.4",
|
|
66
|
+
"typescript": "^5.9.2",
|
|
67
|
+
"vitest": "^4.0.17"
|
|
68
|
+
}
|
|
69
|
+
}
|