@tronsfey/openapi2cli 1.0.10 → 1.0.11
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.md +80 -10
- package/README.zh.md +80 -11
- package/dist/completer.d.ts +11 -0
- package/dist/completer.d.ts.map +1 -0
- package/dist/completer.js +223 -0
- package/dist/completer.js.map +1 -0
- package/dist/index.js +84 -10
- package/dist/index.js.map +1 -1
- package/dist/runner/http-client.d.ts +21 -0
- package/dist/runner/http-client.d.ts.map +1 -0
- package/dist/runner/http-client.js +117 -0
- package/dist/runner/http-client.js.map +1 -0
- package/dist/runner/output.d.ts +2 -0
- package/dist/runner/output.d.ts.map +1 -0
- package/dist/runner/output.js +40 -0
- package/dist/runner/output.js.map +1 -0
- package/dist/runner/proxy-runner.d.ts +11 -0
- package/dist/runner/proxy-runner.d.ts.map +1 -0
- package/dist/runner/proxy-runner.js +256 -0
- package/dist/runner/proxy-runner.js.map +1 -0
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -2,36 +2,68 @@ English | [中文](./README.zh.md)
|
|
|
2
2
|
|
|
3
3
|
# openapi2cli
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Two modes in one tool:
|
|
6
|
+
|
|
7
|
+
1. **Generate** — scaffold a fully typed Commander.js CLI project from an OpenAPI 3.x spec
|
|
8
|
+
2. **Run** — proxy an OpenAPI spec directly from the command line, no code generation needed
|
|
6
9
|
|
|
7
10
|
## Features
|
|
8
11
|
|
|
9
12
|
- Parse OAS 3.x specs from a **file path or URL** (full `$ref` resolution)
|
|
10
13
|
- Group operations by **tag** → Commander subcommand groups; untagged operations become top-level commands
|
|
11
14
|
- Generate **TypeScript source** with correct types, required/optional flags, enum `.choices()` validation
|
|
12
|
-
- **5 auth schemes** auto-detected from OAS security definitions
|
|
13
|
-
- **SSE streaming** via `eventsource-parser`
|
|
15
|
+
- **5 auth schemes** auto-detected from OAS security definitions (generate mode) or via CLI flags (run mode)
|
|
16
|
+
- **SSE streaming** via `eventsource-parser` — full SSE spec support, `[DONE]` sentinel handling
|
|
14
17
|
- **Pagination** via `--all-pages` (follows `Link: rel="next"` response headers)
|
|
15
18
|
- **JMESPath filtering** via `--query` on every command
|
|
16
19
|
- **CJK command names** — Chinese/Japanese/Korean operationIds auto-converted to pinyin
|
|
17
20
|
- **OpenAPI extensions**: `x-cli-name`, `x-cli-aliases`, `x-cli-ignore`, `x-cli-token-url`
|
|
18
21
|
- Generates **bilingual docs**: `README.md` (English) + `README.zh.md` (Chinese) + `SKILL.md` (Claude Code skill descriptor)
|
|
19
|
-
- Global `--endpoint`, `--format` (json/yaml/table), and `--verbose` on every generated CLI
|
|
20
22
|
|
|
21
23
|
## Installation
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
|
-
npm install -g openapi2cli
|
|
26
|
+
npm install -g @tronsfey/openapi2cli
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
## Usage
|
|
28
30
|
|
|
31
|
+
### Run mode (proxy — no code generation)
|
|
32
|
+
|
|
33
|
+
Call any OpenAPI endpoint directly. Auth is passed as CLI flags:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# List available operations
|
|
37
|
+
openapi2cli run --oas ./openapi.yaml
|
|
38
|
+
|
|
39
|
+
# Bearer token
|
|
40
|
+
openapi2cli run --oas ./openapi.yaml --bearer ghp_xxx repos get-repo --owner octocat --repo Hello-World
|
|
41
|
+
|
|
42
|
+
# API key
|
|
43
|
+
openapi2cli run --oas ./openapi.yaml --api-key sk-xxx --api-key-header X-Api-Key pets list-pets
|
|
44
|
+
|
|
45
|
+
# HTTP Basic
|
|
46
|
+
openapi2cli run --oas ./openapi.yaml --basic user:pass users get-user --username alice
|
|
47
|
+
|
|
48
|
+
# Extra headers
|
|
49
|
+
openapi2cli run --oas ./openapi.yaml --header "X-Request-Id: abc123" --header "X-Tenant: acme" ...
|
|
50
|
+
|
|
51
|
+
# Override base URL
|
|
52
|
+
openapi2cli run --oas ./openapi.yaml --endpoint https://staging.example.com --bearer xxx ...
|
|
53
|
+
|
|
54
|
+
# Output options (per operation)
|
|
55
|
+
openapi2cli run --oas ./openapi.yaml repos list-repo-issues --owner octocat --repo Hello-World \
|
|
56
|
+
--format table --query '[].title' --all-pages
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Generate mode (scaffold a typed CLI project)
|
|
60
|
+
|
|
29
61
|
```bash
|
|
30
62
|
# From a local file
|
|
31
|
-
openapi2cli --oas ./openapi.yaml --name my-api --output ./my-api-cli
|
|
63
|
+
openapi2cli generate --oas ./openapi.yaml --name my-api --output ./my-api-cli
|
|
32
64
|
|
|
33
65
|
# From a URL
|
|
34
|
-
openapi2cli --oas https://petstore3.swagger.io/api/v3/openapi.json --name petstore --output ./petstore-cli
|
|
66
|
+
openapi2cli generate --oas https://petstore3.swagger.io/api/v3/openapi.json --name petstore --output ./petstore-cli
|
|
35
67
|
```
|
|
36
68
|
|
|
37
69
|
Build and link the generated project:
|
|
@@ -155,17 +187,55 @@ my-api completions create --model gpt-4o --stream
|
|
|
155
187
|
|
|
156
188
|
The generated client uses `eventsource-parser` with the native `fetch` API. It supports multi-line `data:` payloads, named `event:` types, and silently drops `[DONE]` sentinels used by OpenAI-compatible APIs.
|
|
157
189
|
|
|
158
|
-
##
|
|
190
|
+
## Shell Completion
|
|
191
|
+
|
|
192
|
+
Enable tab-completion in your shell by sourcing the generated script once:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Bash — add to ~/.bashrc
|
|
196
|
+
eval "$(openapi2cli completion bash)"
|
|
197
|
+
|
|
198
|
+
# Zsh — add to ~/.zshrc
|
|
199
|
+
eval "$(openapi2cli completion zsh)"
|
|
159
200
|
|
|
201
|
+
# Fish
|
|
202
|
+
openapi2cli completion fish > ~/.config/fish/completions/openapi2cli.fish
|
|
160
203
|
```
|
|
161
|
-
openapi2cli [options]
|
|
162
204
|
|
|
163
|
-
|
|
205
|
+
Completion covers:
|
|
206
|
+
- Top-level commands (`generate`, `run`, `completion`)
|
|
207
|
+
- All flags for `generate` and `run`
|
|
208
|
+
- **Dynamic operation names** — after `run --oas <spec>` the completion script
|
|
209
|
+
calls `openapi2cli __completions` to look up group and operation names from
|
|
210
|
+
the spec at completion time
|
|
211
|
+
|
|
212
|
+
## CLI Reference
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
openapi2cli generate [options]
|
|
216
|
+
|
|
164
217
|
--oas <path|url> Path or URL to the OpenAPI 3.x spec (required)
|
|
165
218
|
--name <name> CLI executable name (required)
|
|
166
219
|
--output <dir> Output directory (required)
|
|
167
220
|
--overwrite Overwrite existing output directory
|
|
168
221
|
-h, --help Display help
|
|
222
|
+
|
|
223
|
+
openapi2cli run [options] [group] [operation] [operation-options]
|
|
224
|
+
|
|
225
|
+
--oas <path|url> OpenAPI 3.x spec (required)
|
|
226
|
+
--bearer <token> Authorization: Bearer <token>
|
|
227
|
+
--api-key <key> API key value
|
|
228
|
+
--api-key-header <header> Header name for the API key (default: X-Api-Key)
|
|
229
|
+
--basic <user:pass> HTTP Basic credentials
|
|
230
|
+
--header <Name: Value> Extra header, repeatable
|
|
231
|
+
--endpoint <url> Override base URL from the spec
|
|
232
|
+
-h, --help Display help
|
|
233
|
+
|
|
234
|
+
Per-operation output flags (after the operation name):
|
|
235
|
+
--format json|yaml|table Output format (default: json)
|
|
236
|
+
--query <jmespath> Filter response with a JMESPath expression
|
|
237
|
+
--all-pages Auto-paginate via Link rel="next" headers
|
|
238
|
+
--verbose Print HTTP method + URL to stderr
|
|
169
239
|
```
|
|
170
240
|
|
|
171
241
|
## License
|
package/README.zh.md
CHANGED
|
@@ -2,36 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
# openapi2cli
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
两种模式,一个工具:
|
|
6
|
+
|
|
7
|
+
1. **generate(生成)** — 将 OpenAPI 3.x 规范脚手架为完整的 TypeScript CLI 项目
|
|
8
|
+
2. **run(直接代理)** — 无需生成代码,直接在命令行调用 OpenAPI 接口
|
|
6
9
|
|
|
7
10
|
## 功能特性
|
|
8
11
|
|
|
9
12
|
- 支持从**文件路径或 URL** 解析 OAS 3.x 规范(完整 `$ref` 解析)
|
|
10
13
|
- 按 **tag** 分组操作,生成 Commander 子命令组;未分组的操作注册为顶层命令
|
|
11
14
|
- 生成带完整类型标注的 **TypeScript 源码**,支持必填/可选参数、枚举 `.choices()` 校验
|
|
12
|
-
- **5
|
|
13
|
-
- **SSE 流式输出**基于 `eventsource-parser
|
|
15
|
+
- **5 种认证方案**:生成模式从 OAS 安全定义自动检测;run 模式通过命令行参数传入
|
|
16
|
+
- **SSE 流式输出**基于 `eventsource-parser`,支持 `[DONE]` 哨兵处理
|
|
14
17
|
- **自动分页**:`--all-pages` 参数,自动跟随 `Link: rel="next"` 响应头翻页
|
|
15
18
|
- **JMESPath 过滤**:每条命令均支持 `--query` 参数
|
|
16
19
|
- **中文命令名支持**:中/日/韩 operationId 自动转换为拼音
|
|
17
20
|
- **OpenAPI 扩展**:`x-cli-name`、`x-cli-aliases`、`x-cli-ignore`、`x-cli-token-url`
|
|
18
|
-
- 自动生成**双语文档**:`README.md`(英文)+ `README.zh.md`(中文)+ `SKILL.md
|
|
19
|
-
- 所有生成的 CLI 均内置全局选项:`--endpoint`、`--format`(json/yaml/table)、`--verbose`
|
|
21
|
+
- 自动生成**双语文档**:`README.md`(英文)+ `README.zh.md`(中文)+ `SKILL.md`
|
|
20
22
|
|
|
21
23
|
## 安装
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
|
-
npm install -g openapi2cli
|
|
26
|
+
npm install -g @tronsfey/openapi2cli
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
## 使用方法
|
|
28
30
|
|
|
31
|
+
### run 模式(直接代理,无需生成代码)
|
|
32
|
+
|
|
33
|
+
授权信息通过命令行参数传入:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# 列出所有可用操作
|
|
37
|
+
openapi2cli run --oas ./openapi.yaml
|
|
38
|
+
|
|
39
|
+
# Bearer Token
|
|
40
|
+
openapi2cli run --oas ./openapi.yaml --bearer ghp_xxx repos get-repo --owner octocat --repo Hello-World
|
|
41
|
+
|
|
42
|
+
# API Key
|
|
43
|
+
openapi2cli run --oas ./openapi.yaml --api-key sk-xxx --api-key-header X-Api-Key pets list-pets
|
|
44
|
+
|
|
45
|
+
# HTTP Basic
|
|
46
|
+
openapi2cli run --oas ./openapi.yaml --basic user:pass users get-user --username alice
|
|
47
|
+
|
|
48
|
+
# 自定义请求头(可多次指定)
|
|
49
|
+
openapi2cli run --oas ./openapi.yaml --header "X-Request-Id: abc123" --header "X-Tenant: acme" ...
|
|
50
|
+
|
|
51
|
+
# 覆盖 Base URL
|
|
52
|
+
openapi2cli run --oas ./openapi.yaml --endpoint https://staging.example.com --bearer xxx ...
|
|
53
|
+
|
|
54
|
+
# 输出选项(在操作名称之后指定)
|
|
55
|
+
openapi2cli run --oas ./openapi.yaml repos list-repo-issues --owner octocat --repo Hello-World \
|
|
56
|
+
--format table --query '[].title' --all-pages
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### generate 模式(生成完整 CLI 项目)
|
|
60
|
+
|
|
29
61
|
```bash
|
|
30
62
|
# 从本地文件生成
|
|
31
|
-
openapi2cli --oas ./openapi.yaml --name my-api --output ./my-api-cli
|
|
63
|
+
openapi2cli generate --oas ./openapi.yaml --name my-api --output ./my-api-cli
|
|
32
64
|
|
|
33
65
|
# 从 URL 生成
|
|
34
|
-
openapi2cli --oas https://petstore3.swagger.io/api/v3/openapi.json --name petstore --output ./petstore-cli
|
|
66
|
+
openapi2cli generate --oas https://petstore3.swagger.io/api/v3/openapi.json --name petstore --output ./petstore-cli
|
|
35
67
|
```
|
|
36
68
|
|
|
37
69
|
构建并链接生成的项目:
|
|
@@ -155,17 +187,54 @@ my-api completions create --model gpt-4o --stream
|
|
|
155
187
|
|
|
156
188
|
生成的客户端使用 `eventsource-parser`,支持多行 `data:` 载荷、命名 `event:` 类型,并静默丢弃 OpenAI 兼容 API 常用的 `[DONE]` 哨兵。
|
|
157
189
|
|
|
158
|
-
##
|
|
190
|
+
## Shell 自动补全
|
|
191
|
+
|
|
192
|
+
在 shell 中一次性 source 生成的补全脚本,即可启用 Tab 补全:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Bash — 添加到 ~/.bashrc
|
|
196
|
+
eval "$(openapi2cli completion bash)"
|
|
197
|
+
|
|
198
|
+
# Zsh — 添加到 ~/.zshrc
|
|
199
|
+
eval "$(openapi2cli completion zsh)"
|
|
159
200
|
|
|
201
|
+
# Fish
|
|
202
|
+
openapi2cli completion fish > ~/.config/fish/completions/openapi2cli.fish
|
|
160
203
|
```
|
|
161
|
-
openapi2cli [options]
|
|
162
204
|
|
|
163
|
-
|
|
205
|
+
支持补全:
|
|
206
|
+
- 顶层命令(`generate`、`run`、`completion`)
|
|
207
|
+
- `generate` 和 `run` 的所有参数
|
|
208
|
+
- **动态操作名称** — 在 `run --oas <spec>` 之后,补全脚本会调用
|
|
209
|
+
`openapi2cli __completions` 从规范中实时查找命令组和操作名称
|
|
210
|
+
|
|
211
|
+
## 命令行参考
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
openapi2cli generate [options]
|
|
215
|
+
|
|
164
216
|
--oas <path|url> OpenAPI 3.x 规范的文件路径或 URL(必填)
|
|
165
217
|
--name <name> CLI 可执行文件名称(必填)
|
|
166
218
|
--output <dir> 输出目录(必填)
|
|
167
219
|
--overwrite 覆盖已存在的输出目录
|
|
168
220
|
-h, --help 显示帮助信息
|
|
221
|
+
|
|
222
|
+
openapi2cli run [options] [group] [operation] [operation-options]
|
|
223
|
+
|
|
224
|
+
--oas <path|url> OpenAPI 3.x 规范(必填)
|
|
225
|
+
--bearer <token> Authorization: Bearer <token>
|
|
226
|
+
--api-key <key> API Key 值
|
|
227
|
+
--api-key-header <header> API Key 的请求头名称(默认:X-Api-Key)
|
|
228
|
+
--basic <user:pass> HTTP Basic 凭证
|
|
229
|
+
--header <Name: Value> 自定义请求头,可多次指定
|
|
230
|
+
--endpoint <url> 覆盖规范中的 Base URL
|
|
231
|
+
-h, --help 显示帮助信息
|
|
232
|
+
|
|
233
|
+
操作级输出选项(在操作名称之后指定):
|
|
234
|
+
--format json|yaml|table 输出格式(默认:json)
|
|
235
|
+
--query <jmespath> JMESPath 表达式,过滤响应
|
|
236
|
+
--all-pages 自动翻页(跟随 Link rel="next" 响应头)
|
|
237
|
+
--verbose 向 stderr 打印 HTTP 方法和 URL
|
|
169
238
|
```
|
|
170
239
|
|
|
171
240
|
## 许可证
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell completion script generators for openapi2cli.
|
|
3
|
+
*
|
|
4
|
+
* Each function returns a string that can be sourced by the user's shell.
|
|
5
|
+
* Dynamic operation completion (after `run --oas <spec>`) is handled by
|
|
6
|
+
* calling back into the hidden `__completions` subcommand.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateBashCompletion(): string;
|
|
9
|
+
export declare function generateZshCompletion(): string;
|
|
10
|
+
export declare function generateFishCompletion(): string;
|
|
11
|
+
//# sourceMappingURL=completer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completer.d.ts","sourceRoot":"","sources":["../src/completer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,wBAAgB,sBAAsB,IAAI,MAAM,CAyE/C;AAID,wBAAgB,qBAAqB,IAAI,MAAM,CAyF9C;AAID,wBAAgB,sBAAsB,IAAI,MAAM,CAsC/C"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shell completion script generators for openapi2cli.
|
|
4
|
+
*
|
|
5
|
+
* Each function returns a string that can be sourced by the user's shell.
|
|
6
|
+
* Dynamic operation completion (after `run --oas <spec>`) is handled by
|
|
7
|
+
* calling back into the hidden `__completions` subcommand.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.generateBashCompletion = generateBashCompletion;
|
|
11
|
+
exports.generateZshCompletion = generateZshCompletion;
|
|
12
|
+
exports.generateFishCompletion = generateFishCompletion;
|
|
13
|
+
const RUN_FLAGS = '--oas --bearer --api-key --api-key-header --basic --header --endpoint --help';
|
|
14
|
+
const GENERATE_FLAGS = '--oas --name --output --overwrite --help';
|
|
15
|
+
const TOP_COMMANDS = 'generate run completion help';
|
|
16
|
+
const COMPLETION_SHELLS = 'bash zsh fish';
|
|
17
|
+
// ─── Bash ─────────────────────────────────────────────────────────────────────
|
|
18
|
+
function generateBashCompletion() {
|
|
19
|
+
return [
|
|
20
|
+
'# bash completion for openapi2cli',
|
|
21
|
+
'# Source this file or add the following line to ~/.bashrc / ~/.bash_profile:',
|
|
22
|
+
'# eval "$(openapi2cli completion bash)"',
|
|
23
|
+
'',
|
|
24
|
+
'_openapi2cli() {',
|
|
25
|
+
' local cur prev words cword',
|
|
26
|
+
' _init_completion 2>/dev/null || {',
|
|
27
|
+
' COMPREPLY=()',
|
|
28
|
+
' cur="${COMP_WORDS[COMP_CWORD]}"',
|
|
29
|
+
' prev="${COMP_WORDS[COMP_CWORD-1]}"',
|
|
30
|
+
' words=("${COMP_WORDS[@]}")',
|
|
31
|
+
' cword=$COMP_CWORD',
|
|
32
|
+
' }',
|
|
33
|
+
'',
|
|
34
|
+
' # Find the subcommand (first non-flag word after "openapi2cli")',
|
|
35
|
+
' local subcmd=""',
|
|
36
|
+
' local oas_path=""',
|
|
37
|
+
' local group=""',
|
|
38
|
+
' local i',
|
|
39
|
+
' for ((i=1; i<cword; i++)); do',
|
|
40
|
+
' case "${words[i]}" in',
|
|
41
|
+
' --oas) oas_path="${words[i+1]:-}"; ((i++)) ;;',
|
|
42
|
+
' generate|run|completion) subcmd="${words[i]}" ;;',
|
|
43
|
+
' --*) ;; # skip other flags',
|
|
44
|
+
' *) [[ -n "$subcmd" && -z "$group" ]] && group="${words[i]}" ;;',
|
|
45
|
+
' esac',
|
|
46
|
+
' done',
|
|
47
|
+
'',
|
|
48
|
+
' case "$prev" in',
|
|
49
|
+
' --oas|--output)',
|
|
50
|
+
' COMPREPLY=($(compgen -f -- "$cur"))',
|
|
51
|
+
' return ;;',
|
|
52
|
+
' --format)',
|
|
53
|
+
' COMPREPLY=($(compgen -W "json yaml table" -- "$cur"))',
|
|
54
|
+
' return ;;',
|
|
55
|
+
' --api-key-header)',
|
|
56
|
+
' COMPREPLY=($(compgen -W "X-Api-Key Authorization X-Token" -- "$cur"))',
|
|
57
|
+
' return ;;',
|
|
58
|
+
' completion)',
|
|
59
|
+
` COMPREPLY=($(compgen -W "${COMPLETION_SHELLS}" -- "$cur"))`,
|
|
60
|
+
' return ;;',
|
|
61
|
+
' esac',
|
|
62
|
+
'',
|
|
63
|
+
' case "$subcmd" in',
|
|
64
|
+
' "")',
|
|
65
|
+
` COMPREPLY=($(compgen -W "${TOP_COMMANDS}" -- "$cur"))`,
|
|
66
|
+
' ;;',
|
|
67
|
+
' generate)',
|
|
68
|
+
` COMPREPLY=($(compgen -W "${GENERATE_FLAGS}" -- "$cur"))`,
|
|
69
|
+
' ;;',
|
|
70
|
+
' run)',
|
|
71
|
+
' if [[ -n "$oas_path" && -n "$group" ]]; then',
|
|
72
|
+
' # Complete operation names within the group',
|
|
73
|
+
' local ops',
|
|
74
|
+
' ops=$(openapi2cli __completions --oas "$oas_path" --group "$group" 2>/dev/null)',
|
|
75
|
+
' COMPREPLY=($(compgen -W "$ops" -- "$cur"))',
|
|
76
|
+
' elif [[ -n "$oas_path" && "$cur" != -* ]]; then',
|
|
77
|
+
' # Complete group names',
|
|
78
|
+
' local groups',
|
|
79
|
+
' groups=$(openapi2cli __completions --oas "$oas_path" 2>/dev/null)',
|
|
80
|
+
' COMPREPLY=($(compgen -W "$groups" -- "$cur"))',
|
|
81
|
+
' else',
|
|
82
|
+
` COMPREPLY=($(compgen -W "${RUN_FLAGS}" -- "$cur"))`,
|
|
83
|
+
' fi',
|
|
84
|
+
' ;;',
|
|
85
|
+
' esac',
|
|
86
|
+
'}',
|
|
87
|
+
'',
|
|
88
|
+
'complete -F _openapi2cli openapi2cli',
|
|
89
|
+
'',
|
|
90
|
+
].join('\n');
|
|
91
|
+
}
|
|
92
|
+
// ─── Zsh ──────────────────────────────────────────────────────────────────────
|
|
93
|
+
function generateZshCompletion() {
|
|
94
|
+
return [
|
|
95
|
+
'#compdef openapi2cli',
|
|
96
|
+
'# zsh completion for openapi2cli',
|
|
97
|
+
'# Source this file or add the following to ~/.zshrc:',
|
|
98
|
+
'# eval "$(openapi2cli completion zsh)"',
|
|
99
|
+
'',
|
|
100
|
+
'_openapi2cli() {',
|
|
101
|
+
' local state line',
|
|
102
|
+
' typeset -A opt_args',
|
|
103
|
+
'',
|
|
104
|
+
' _arguments -C \\',
|
|
105
|
+
" '(-h --help)'{-h,--help}'[Show help]' \\",
|
|
106
|
+
" '(-V --version)'{-V,--version}'[Show version]' \\",
|
|
107
|
+
" '1: :->subcmd' \\",
|
|
108
|
+
" '*:: :->args'",
|
|
109
|
+
'',
|
|
110
|
+
' case $state in',
|
|
111
|
+
' subcmd)',
|
|
112
|
+
' local -a cmds',
|
|
113
|
+
' cmds=(',
|
|
114
|
+
" 'generate:Generate a Commander.js CLI project from an OpenAPI spec'",
|
|
115
|
+
" 'run:Directly call an OpenAPI endpoint without generating code'",
|
|
116
|
+
" 'completion:Output shell completion script'",
|
|
117
|
+
" 'help:Display help'",
|
|
118
|
+
' )',
|
|
119
|
+
" _describe 'command' cmds",
|
|
120
|
+
' ;;',
|
|
121
|
+
' args)',
|
|
122
|
+
' case $line[1] in',
|
|
123
|
+
' generate)',
|
|
124
|
+
' _arguments \\',
|
|
125
|
+
" '--oas[Path or URL to the OpenAPI spec file]:spec:_files' \\",
|
|
126
|
+
" '--name[CLI executable name]:name' \\",
|
|
127
|
+
" '--output[Output directory]:dir:_files -/' \\",
|
|
128
|
+
" '--overwrite[Overwrite existing output directory]' \\",
|
|
129
|
+
" '(-h --help)'{-h,--help}'[Show help]'",
|
|
130
|
+
' ;;',
|
|
131
|
+
' run)',
|
|
132
|
+
' _arguments -C \\',
|
|
133
|
+
" '--oas[Path or URL to the OpenAPI spec file]:spec:_files' \\",
|
|
134
|
+
" '--bearer[Bearer token]:token' \\",
|
|
135
|
+
" '--api-key[API key value]:key' \\",
|
|
136
|
+
" '--api-key-header[API key header name]:header:(X-Api-Key Authorization X-Token)' \\",
|
|
137
|
+
" '--basic[HTTP Basic credentials (user\\:pass)]:credentials' \\",
|
|
138
|
+
" '--header[Extra HTTP header (Name\\: Value)]:header' \\",
|
|
139
|
+
" '--endpoint[Override base URL]:url' \\",
|
|
140
|
+
" '(-h --help)'{-h,--help}'[Show help]' \\",
|
|
141
|
+
" '1: :->group' \\",
|
|
142
|
+
" '2: :->operation' \\",
|
|
143
|
+
" '*:: :->op_args'",
|
|
144
|
+
'',
|
|
145
|
+
' local oas_path="${opt_args[--oas]}"',
|
|
146
|
+
'',
|
|
147
|
+
' case $state in',
|
|
148
|
+
' group)',
|
|
149
|
+
' if [[ -n "$oas_path" ]]; then',
|
|
150
|
+
' local -a groups',
|
|
151
|
+
' groups=($(openapi2cli __completions --oas "$oas_path" 2>/dev/null))',
|
|
152
|
+
" _describe 'command group' groups",
|
|
153
|
+
' fi',
|
|
154
|
+
' ;;',
|
|
155
|
+
' operation)',
|
|
156
|
+
' if [[ -n "$oas_path" && -n "$line[1]" ]]; then',
|
|
157
|
+
' local -a ops',
|
|
158
|
+
' ops=($(openapi2cli __completions --oas "$oas_path" --group "$line[1]" 2>/dev/null))',
|
|
159
|
+
" _describe 'operation' ops",
|
|
160
|
+
' fi',
|
|
161
|
+
' ;;',
|
|
162
|
+
' op_args)',
|
|
163
|
+
' _arguments \\',
|
|
164
|
+
" '--format[Output format]:fmt:(json yaml table)' \\",
|
|
165
|
+
" '--query[JMESPath expression]:expr' \\",
|
|
166
|
+
" '--all-pages[Auto-paginate]' \\",
|
|
167
|
+
" '--verbose[Log HTTP method and URL]'",
|
|
168
|
+
' ;;',
|
|
169
|
+
' esac',
|
|
170
|
+
' ;;',
|
|
171
|
+
' completion)',
|
|
172
|
+
" _arguments '1: :(bash zsh fish)'",
|
|
173
|
+
' ;;',
|
|
174
|
+
' esac',
|
|
175
|
+
' ;;',
|
|
176
|
+
' esac',
|
|
177
|
+
'}',
|
|
178
|
+
'',
|
|
179
|
+
'_openapi2cli "$@"',
|
|
180
|
+
'',
|
|
181
|
+
].join('\n');
|
|
182
|
+
}
|
|
183
|
+
// ─── Fish ─────────────────────────────────────────────────────────────────────
|
|
184
|
+
function generateFishCompletion() {
|
|
185
|
+
return [
|
|
186
|
+
'# fish completion for openapi2cli',
|
|
187
|
+
'# Save this file to: ~/.config/fish/completions/openapi2cli.fish',
|
|
188
|
+
'# Or run: openapi2cli completion fish > ~/.config/fish/completions/openapi2cli.fish',
|
|
189
|
+
'',
|
|
190
|
+
'# Disable file completions for the main command',
|
|
191
|
+
'complete -c openapi2cli -f',
|
|
192
|
+
'',
|
|
193
|
+
'# Top-level subcommands',
|
|
194
|
+
"complete -c openapi2cli -n '__fish_use_subcommand' -a 'generate' -d 'Generate a CLI project from an OpenAPI spec'",
|
|
195
|
+
"complete -c openapi2cli -n '__fish_use_subcommand' -a 'run' -d 'Call an OpenAPI endpoint directly'",
|
|
196
|
+
"complete -c openapi2cli -n '__fish_use_subcommand' -a 'completion' -d 'Output shell completion script'",
|
|
197
|
+
"complete -c openapi2cli -n '__fish_use_subcommand' -a 'help' -d 'Display help'",
|
|
198
|
+
'',
|
|
199
|
+
'# generate flags',
|
|
200
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from generate' -l oas -r -d 'Path or URL to the OpenAPI spec'",
|
|
201
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from generate' -l name -r -d 'CLI executable name'",
|
|
202
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from generate' -l output -r -d 'Output directory'",
|
|
203
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from generate' -l overwrite -d 'Overwrite existing output'",
|
|
204
|
+
'',
|
|
205
|
+
'# run flags',
|
|
206
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l oas -r -d 'Path or URL to the OpenAPI spec'",
|
|
207
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l bearer -r -d 'Bearer token'",
|
|
208
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l api-key -r -d 'API key value'",
|
|
209
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l api-key-header -r -d 'API key header name'",
|
|
210
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l basic -r -d 'HTTP Basic credentials (user:pass)'",
|
|
211
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l header -r -d 'Extra HTTP header (Name: Value)'",
|
|
212
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l endpoint -r -d 'Override base URL'",
|
|
213
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l format -r -d 'Output format' -a 'json yaml table'",
|
|
214
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l query -r -d 'JMESPath expression'",
|
|
215
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l all-pages -d 'Auto-paginate'",
|
|
216
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from run' -l verbose -d 'Log HTTP method and URL'",
|
|
217
|
+
'',
|
|
218
|
+
'# completion shells',
|
|
219
|
+
"complete -c openapi2cli -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish' -d 'Shell type'",
|
|
220
|
+
'',
|
|
221
|
+
].join('\n');
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=completer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completer.js","sourceRoot":"","sources":["../src/completer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAS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AY;QACZ,UAAU;QACV,QAAQ;QACR,GAAG;QACH,EAAE;QACF,mBAAmB;QACnB,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,iFAAiF;AAEjF,SAAgB,sBAAsB;IACpC,OAAO;QACL,mCAAmC;QACnC,kEAAkE;QAClE,qFAAqF;QACrF,EAAE;QACF,iDAAiD;QACjD,4BAA4B;QAC5B,EAAE;QACF,yBAAyB;QACzB,oHAAoH;QACpH,0GAA0G;QAC1G,wGAAwG;QACxG,qFAAqF;QACrF,EAAE;QACF,kBAAkB;QAClB,wHAAwH;QACxH,4GAA4G;QAC5G,yGAAyG;QACzG,mHAAmH;QACnH,EAAE;QACF,aAAa;QACb,wHAAwH;QACxH,qGAAqG;QACrG,sGAAsG;QACtG,4GAA4G;QAC5G,2HAA2H;QAC3H,wHAAwH;QACxH,0GAA0G;QAC1G,2HAA2H;QAC3H,4GAA4G;QAC5G,uGAAuG;QACvG,iHAAiH;QACjH,EAAE;QACF,qBAAqB;QACrB,wGAAwG;QACxG,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -45,25 +45,105 @@ const path = __importStar(require("path"));
|
|
|
45
45
|
const oas_parser_1 = require("./parser/oas-parser");
|
|
46
46
|
const schema_analyzer_1 = require("./analyzer/schema-analyzer");
|
|
47
47
|
const command_generator_1 = require("./generator/command-generator");
|
|
48
|
+
const proxy_runner_1 = require("./runner/proxy-runner");
|
|
49
|
+
const completer_1 = require("./completer");
|
|
48
50
|
const program = new commander_1.Command();
|
|
49
51
|
program
|
|
50
52
|
.name('openapi2cli')
|
|
51
|
-
.description('Generate a typed CLI from an OpenAPI 3.x specification')
|
|
53
|
+
.description('Generate a typed CLI from an OpenAPI 3.x specification, or proxy one directly')
|
|
52
54
|
.version('1.0.0')
|
|
55
|
+
.enablePositionalOptions(true);
|
|
56
|
+
// ─── generate ────────────────────────────────────────────────────────────────
|
|
57
|
+
program
|
|
58
|
+
.command('generate')
|
|
59
|
+
.description('Generate a Commander.js CLI project from an OpenAPI spec')
|
|
53
60
|
.requiredOption('--oas <path-or-url>', 'Path or URL to the OpenAPI spec file')
|
|
54
61
|
.requiredOption('--name <cli-name>', 'Name for the generated CLI tool')
|
|
55
62
|
.requiredOption('--output <dir>', 'Output directory for the generated project')
|
|
56
63
|
.option('--overwrite', 'Overwrite output directory if it exists', false)
|
|
57
64
|
.action(async (opts) => {
|
|
58
|
-
await
|
|
65
|
+
await generate(opts);
|
|
66
|
+
});
|
|
67
|
+
// ─── run (proxy mode) ────────────────────────────────────────────────────────
|
|
68
|
+
program
|
|
69
|
+
.command('run', { isDefault: false })
|
|
70
|
+
.description('Directly call an OpenAPI endpoint without generating code')
|
|
71
|
+
.requiredOption('--oas <path-or-url>', 'Path or URL to the OpenAPI spec file')
|
|
72
|
+
.option('--bearer <token>', 'Bearer token → Authorization: Bearer <token>')
|
|
73
|
+
.option('--api-key <key>', 'API key value')
|
|
74
|
+
.option('--api-key-header <header>', 'Header name for API key (default: X-Api-Key)', 'X-Api-Key')
|
|
75
|
+
.option('--basic <credentials>', 'HTTP Basic credentials (user:password)')
|
|
76
|
+
.option('--header <header>', 'Extra HTTP header "Name: Value" (repeatable)', collect, [])
|
|
77
|
+
.option('--endpoint <url>', 'Override base URL from the spec')
|
|
78
|
+
.allowUnknownOption(true)
|
|
79
|
+
.passThroughOptions(true)
|
|
80
|
+
.action(async function (opts) {
|
|
81
|
+
const remaining = this.args;
|
|
82
|
+
await (0, proxy_runner_1.proxyRun)(opts, remaining);
|
|
83
|
+
});
|
|
84
|
+
// ─── completion ──────────────────────────────────────────────────────────────
|
|
85
|
+
program
|
|
86
|
+
.command('completion [shell]')
|
|
87
|
+
.description('Output shell completion script (bash, zsh, fish)')
|
|
88
|
+
.action((shell) => {
|
|
89
|
+
const s = (shell ?? 'bash').toLowerCase();
|
|
90
|
+
if (s === 'bash') {
|
|
91
|
+
process.stdout.write((0, completer_1.generateBashCompletion)());
|
|
92
|
+
}
|
|
93
|
+
else if (s === 'zsh') {
|
|
94
|
+
process.stdout.write((0, completer_1.generateZshCompletion)());
|
|
95
|
+
}
|
|
96
|
+
else if (s === 'fish') {
|
|
97
|
+
process.stdout.write((0, completer_1.generateFishCompletion)());
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.error(chalk_1.default.red('Unknown shell:'), shell);
|
|
101
|
+
console.error('Supported shells: bash, zsh, fish');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
// ─── __completions (hidden — used by completion scripts) ─────────────────────
|
|
106
|
+
program
|
|
107
|
+
.command('__completions', { hidden: true })
|
|
108
|
+
.option('--oas <path>', 'Path or URL to the OpenAPI spec')
|
|
109
|
+
.option('--group <group>', 'Return operation names for this group')
|
|
110
|
+
.option('--flat', 'Return flat (untagged) operation names')
|
|
111
|
+
.action(async (opts) => {
|
|
112
|
+
if (!opts.oas)
|
|
113
|
+
return;
|
|
114
|
+
try {
|
|
115
|
+
const api = await (0, oas_parser_1.parseOAS)(opts.oas);
|
|
116
|
+
const structure = (0, schema_analyzer_1.analyzeSchema)(api, '_proxy_');
|
|
117
|
+
if (opts.group) {
|
|
118
|
+
const g = structure.groups.find(gr => gr.name === opts.group);
|
|
119
|
+
if (g)
|
|
120
|
+
process.stdout.write(g.subcommands.map(s => s.name).join('\n') + '\n');
|
|
121
|
+
}
|
|
122
|
+
else if (opts.flat) {
|
|
123
|
+
process.stdout.write(structure.flatCommands.map(s => s.name).join('\n') + '\n');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
process.stdout.write(structure.groups.map(g => g.name).join('\n') + '\n');
|
|
127
|
+
if (structure.flatCommands.length > 0) {
|
|
128
|
+
process.stdout.write(structure.flatCommands.map(s => s.name).join('\n') + '\n');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Silently fail — completion should never break the user's shell
|
|
134
|
+
}
|
|
59
135
|
});
|
|
60
136
|
program.parseAsync(process.argv).catch((err) => {
|
|
61
137
|
console.error(chalk_1.default.red('Fatal:'), err.message);
|
|
62
138
|
process.exit(1);
|
|
63
139
|
});
|
|
64
|
-
|
|
140
|
+
// ─── helpers ─────────────────────────────────────────────────────────────────
|
|
141
|
+
function collect(val, acc) {
|
|
142
|
+
acc.push(val);
|
|
143
|
+
return acc;
|
|
144
|
+
}
|
|
145
|
+
async function generate(opts) {
|
|
65
146
|
const outputDir = path.resolve(process.cwd(), opts.output);
|
|
66
|
-
// Pre-flight: check output directory
|
|
67
147
|
if (await fse.pathExists(outputDir)) {
|
|
68
148
|
if (!opts.overwrite) {
|
|
69
149
|
console.error(chalk_1.default.red('Error:'), `Output directory already exists: ${outputDir}`);
|
|
@@ -72,7 +152,6 @@ async function run(opts) {
|
|
|
72
152
|
}
|
|
73
153
|
await fse.remove(outputDir);
|
|
74
154
|
}
|
|
75
|
-
// Step 1: Parse OAS
|
|
76
155
|
const parseSpinner = (0, ora_1.default)('Parsing OpenAPI spec...').start();
|
|
77
156
|
let api;
|
|
78
157
|
try {
|
|
@@ -83,7 +162,6 @@ async function run(opts) {
|
|
|
83
162
|
parseSpinner.fail('Failed to parse OpenAPI spec');
|
|
84
163
|
throw err;
|
|
85
164
|
}
|
|
86
|
-
// Step 2: Analyze schema
|
|
87
165
|
const analyzeSpinner = (0, ora_1.default)('Analyzing schema...').start();
|
|
88
166
|
const structure = (0, schema_analyzer_1.analyzeSchema)(api, opts.name);
|
|
89
167
|
const groupCount = structure.groups.length;
|
|
@@ -93,7 +171,6 @@ async function run(opts) {
|
|
|
93
171
|
flatCount > 0 ? `${flatCount} flat command(s)` : '',
|
|
94
172
|
].filter(Boolean).join(', ');
|
|
95
173
|
analyzeSpinner.succeed(chalk_1.default.green(`Found ${summary}`));
|
|
96
|
-
// Print any naming warnings collected during analysis
|
|
97
174
|
if (structure.warnings.length > 0) {
|
|
98
175
|
console.log('');
|
|
99
176
|
console.log(chalk_1.default.yellow(' ⚠ 规范性警告 (建议修复 OpenAPI 定义):'));
|
|
@@ -102,7 +179,6 @@ async function run(opts) {
|
|
|
102
179
|
}
|
|
103
180
|
console.log('');
|
|
104
181
|
}
|
|
105
|
-
// Step 3: Generate project files
|
|
106
182
|
const genSpinner = (0, ora_1.default)('Generating project files...').start();
|
|
107
183
|
let files;
|
|
108
184
|
try {
|
|
@@ -113,13 +189,11 @@ async function run(opts) {
|
|
|
113
189
|
genSpinner.fail('Failed to generate project files');
|
|
114
190
|
throw err;
|
|
115
191
|
}
|
|
116
|
-
// Step 4: Write files to output directory
|
|
117
192
|
const writeSpinner = (0, ora_1.default)(`Writing to ${outputDir}...`).start();
|
|
118
193
|
for (const file of files) {
|
|
119
194
|
const dest = path.join(outputDir, file.relativePath);
|
|
120
195
|
await fse.outputFile(dest, file.content, 'utf-8');
|
|
121
196
|
}
|
|
122
|
-
// Make the bin file executable
|
|
123
197
|
const binPath = path.join(outputDir, 'bin', opts.name);
|
|
124
198
|
if (await fse.pathExists(binPath)) {
|
|
125
199
|
await fse.chmod(binPath, 0o755);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,8CAAgC;AAChC,2CAA6B;AAC7B,oDAA+C;AAC/C,gEAA2D;AAC3D,qEAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,8CAAgC;AAChC,2CAA6B;AAC7B,oDAA+C;AAC/C,gEAA2D;AAC3D,qEAAgE;AAEhE,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,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface RuntimeAuth {
|
|
2
|
+
bearer?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
apiKeyHeader?: string;
|
|
5
|
+
basic?: string;
|
|
6
|
+
extraHeaders?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface RequestOptions {
|
|
9
|
+
method: string;
|
|
10
|
+
path: string;
|
|
11
|
+
pathParams: Record<string, string>;
|
|
12
|
+
queryParams: Record<string, string>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
allPages?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function createRuntimeClient(baseURL: string, auth: RuntimeAuth): {
|
|
18
|
+
request({ method, path, pathParams, queryParams, body, verbose, allPages }: RequestOptions): Promise<unknown>;
|
|
19
|
+
requestStream({ method, path, pathParams, queryParams, body, verbose }: RequestOptions): AsyncGenerator<string, void, unknown>;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/runner/http-client.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAkCD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW;gFAIgB,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;4EAwCpC,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;EA8BxI"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createRuntimeClient = createRuntimeClient;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const stream_1 = require("eventsource-parser/stream");
|
|
10
|
+
function buildAuthHeaders(auth) {
|
|
11
|
+
const headers = {};
|
|
12
|
+
if (auth.bearer) {
|
|
13
|
+
headers['Authorization'] = `Bearer ${auth.bearer}`;
|
|
14
|
+
}
|
|
15
|
+
else if (auth.apiKey) {
|
|
16
|
+
headers[auth.apiKeyHeader ?? 'X-Api-Key'] = auth.apiKey;
|
|
17
|
+
}
|
|
18
|
+
else if (auth.basic) {
|
|
19
|
+
headers['Authorization'] = `Basic ${Buffer.from(auth.basic).toString('base64')}`;
|
|
20
|
+
}
|
|
21
|
+
for (const [k, v] of Object.entries(auth.extraHeaders ?? {})) {
|
|
22
|
+
headers[k] = v;
|
|
23
|
+
}
|
|
24
|
+
return headers;
|
|
25
|
+
}
|
|
26
|
+
function buildUrl(pathTemplate, pathParams) {
|
|
27
|
+
return pathTemplate.replace(/\{(\w+)\}/g, (_, key) => {
|
|
28
|
+
const val = pathParams[key];
|
|
29
|
+
if (val === undefined)
|
|
30
|
+
throw new Error(`Missing required path parameter: ${key}`);
|
|
31
|
+
return encodeURIComponent(val);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function parseLinkNext(linkHeader) {
|
|
35
|
+
if (!linkHeader)
|
|
36
|
+
return null;
|
|
37
|
+
for (const part of linkHeader.split(',')) {
|
|
38
|
+
const match = part.match(/<([^>]+)>;\s*rel="next"/);
|
|
39
|
+
if (match)
|
|
40
|
+
return match[1];
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
function createRuntimeClient(baseURL, auth) {
|
|
45
|
+
const instance = axios_1.default.create({ baseURL, proxy: false });
|
|
46
|
+
return {
|
|
47
|
+
async request({ method, path, pathParams, queryParams, body, verbose, allPages }) {
|
|
48
|
+
const url = buildUrl(path, pathParams);
|
|
49
|
+
const authHeaders = buildAuthHeaders(auth);
|
|
50
|
+
const config = {
|
|
51
|
+
method,
|
|
52
|
+
url,
|
|
53
|
+
params: Object.keys(queryParams).length ? queryParams : undefined,
|
|
54
|
+
data: body,
|
|
55
|
+
headers: authHeaders,
|
|
56
|
+
};
|
|
57
|
+
if (verbose) {
|
|
58
|
+
console.error(chalk_1.default.dim('→'), chalk_1.default.bold(method.toUpperCase()), baseURL + url);
|
|
59
|
+
if (body !== undefined)
|
|
60
|
+
console.error(chalk_1.default.dim(' body:'), JSON.stringify(body));
|
|
61
|
+
}
|
|
62
|
+
if (allPages) {
|
|
63
|
+
const results = [];
|
|
64
|
+
let nextUrl = url;
|
|
65
|
+
let isFirst = true;
|
|
66
|
+
while (nextUrl) {
|
|
67
|
+
const pageConfig = isFirst
|
|
68
|
+
? { ...config }
|
|
69
|
+
: { method, url: nextUrl, headers: authHeaders };
|
|
70
|
+
isFirst = false;
|
|
71
|
+
const response = await instance.request(pageConfig);
|
|
72
|
+
if (verbose)
|
|
73
|
+
console.error(chalk_1.default.dim('←'), chalk_1.default.bold(String(response.status)), response.statusText);
|
|
74
|
+
const data = response.data;
|
|
75
|
+
if (Array.isArray(data))
|
|
76
|
+
results.push(...data);
|
|
77
|
+
else
|
|
78
|
+
results.push(data);
|
|
79
|
+
nextUrl = parseLinkNext(response.headers['link']);
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
const response = await instance.request(config);
|
|
84
|
+
if (verbose)
|
|
85
|
+
console.error(chalk_1.default.dim('←'), chalk_1.default.bold(String(response.status)), response.statusText);
|
|
86
|
+
return response.data;
|
|
87
|
+
},
|
|
88
|
+
async *requestStream({ method, path, pathParams, queryParams, body, verbose }) {
|
|
89
|
+
const url = buildUrl(path, pathParams);
|
|
90
|
+
const qs = new URLSearchParams(queryParams).toString();
|
|
91
|
+
const fullUrl = baseURL + url + (qs ? `?${qs}` : '');
|
|
92
|
+
const authHeaders = buildAuthHeaders(auth);
|
|
93
|
+
if (verbose)
|
|
94
|
+
console.error(chalk_1.default.dim('→ SSE'), chalk_1.default.bold(method.toUpperCase()), fullUrl);
|
|
95
|
+
const response = await fetch(fullUrl, {
|
|
96
|
+
method,
|
|
97
|
+
headers: { Accept: 'text/event-stream', 'Cache-Control': 'no-cache', ...authHeaders },
|
|
98
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok)
|
|
101
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
102
|
+
if (!response.body)
|
|
103
|
+
return;
|
|
104
|
+
if (verbose)
|
|
105
|
+
console.error(chalk_1.default.dim('← SSE'), chalk_1.default.bold(String(response.status)), response.statusText);
|
|
106
|
+
const eventStream = response.body
|
|
107
|
+
.pipeThrough(new TextDecoderStream())
|
|
108
|
+
.pipeThrough(new stream_1.EventSourceParserStream());
|
|
109
|
+
for await (const event of eventStream) {
|
|
110
|
+
if (event.data && event.data !== '[DONE]') {
|
|
111
|
+
yield event.data;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/runner/http-client.ts"],"names":[],"mappings":";;;;;AAsDA,kDA0EC;AAhID,kDAAgF;AAChF,kDAA0B;AAC1B,sDAAoE;AAoBpE,SAAS,gBAAgB,CAAC,IAAiB;IACzC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;IACrD,CAAC;SAAM,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,YAAY,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;SAAM,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CA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;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/runner/output.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CA0BhF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatOutput = formatOutput;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
const jmespath_1 = __importDefault(require("jmespath"));
|
|
10
|
+
function formatOutput(data, format, query) {
|
|
11
|
+
let result = data;
|
|
12
|
+
if (query) {
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
result = jmespath_1.default.search(data, query);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.error(chalk_1.default.red('JMESPath error:'), e.message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (format === 'yaml') {
|
|
23
|
+
console.log((0, yaml_1.stringify)(result));
|
|
24
|
+
}
|
|
25
|
+
else if (format === 'table') {
|
|
26
|
+
if (Array.isArray(result) && result.length > 0 && typeof result[0] === 'object') {
|
|
27
|
+
console.table(result);
|
|
28
|
+
}
|
|
29
|
+
else if (typeof result === 'object' && result !== null) {
|
|
30
|
+
console.table(result);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.log(String(result));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log(JSON.stringify(result, null, 2));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/runner/output.ts"],"names":[],"mappings":";;;;;AAIA,oCA0BC;AA9BD,kDAA0B;AAC1B,+BAAkD;AAClD,wDAAgC;AAEhC,SAAgB,YAAY,CAAC,IAAa,EAAE,MAAc,EAAE,KAAc;IACxE,IAAI,MAAM,GAAY,IAAI,CAAC;IAE3B,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC;YACH,8DAA8D;YAC9D,MAAM,GAAG,kBAAQ,CAAC,MAAM,CAAC,IAAW,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAG,CAAW,CAAC,OAAO,CAAC,CAAC;YAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,IAAA,gBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;IACrC,CAAC;SAAM,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YAChF,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACzD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ProxyOpts {
|
|
2
|
+
oas: string;
|
|
3
|
+
bearer?: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
apiKeyHeader?: string;
|
|
6
|
+
basic?: string;
|
|
7
|
+
header?: string[];
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function proxyRun(proxyOpts: ProxyOpts, remainingArgs: string[]): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=proxy-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-runner.d.ts","sourceRoot":"","sources":["../../src/runner/proxy-runner.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA4LD,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.proxyRun = proxyRun;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
43
|
+
const fse = __importStar(require("fs-extra"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const oas_parser_1 = require("../parser/oas-parser");
|
|
46
|
+
const schema_analyzer_1 = require("../analyzer/schema-analyzer");
|
|
47
|
+
const http_client_1 = require("./http-client");
|
|
48
|
+
const output_1 = require("./output");
|
|
49
|
+
// Parse "Name: Value" strings into a header map.
|
|
50
|
+
function parseExtraHeaders(headers) {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const h of headers ?? []) {
|
|
53
|
+
const idx = h.indexOf(':');
|
|
54
|
+
if (idx === -1)
|
|
55
|
+
continue;
|
|
56
|
+
result[h.slice(0, idx).trim()] = h.slice(idx + 1).trim();
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
// Commander stores option values with camelCase keys derived from the flag name.
|
|
61
|
+
// e.g., --per-page → opts.perPage, --owner → opts.owner
|
|
62
|
+
function optsKey(flagName) {
|
|
63
|
+
return lodash_1.default.camelCase(flagName);
|
|
64
|
+
}
|
|
65
|
+
// Build and execute the HTTP call for a matched operation.
|
|
66
|
+
async function executeOperation(sub, opts, client) {
|
|
67
|
+
const verbose = opts['verbose'] ?? false;
|
|
68
|
+
const format = opts['format'] ?? 'json';
|
|
69
|
+
const query = opts['query'];
|
|
70
|
+
const allPages = opts['allPages'] ?? false;
|
|
71
|
+
const pathParams = {};
|
|
72
|
+
const queryParams = {};
|
|
73
|
+
for (const param of sub.parameters) {
|
|
74
|
+
const key = optsKey(lodash_1.default.kebabCase(param.name));
|
|
75
|
+
const val = opts[key];
|
|
76
|
+
if (val === undefined || val === null)
|
|
77
|
+
continue;
|
|
78
|
+
if (param.in === 'path') {
|
|
79
|
+
pathParams[param.name] = String(val);
|
|
80
|
+
}
|
|
81
|
+
else if (param.in === 'query') {
|
|
82
|
+
queryParams[param.name] = String(val);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// --data raw override: short-circuit individual body field options
|
|
86
|
+
if (opts['data'] !== undefined) {
|
|
87
|
+
const rawData = opts['data'];
|
|
88
|
+
let body;
|
|
89
|
+
if (rawData.startsWith('@')) {
|
|
90
|
+
const filePath = path.resolve(process.cwd(), rawData.slice(1));
|
|
91
|
+
body = JSON.parse(await fse.readFile(filePath, 'utf-8'));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
body = JSON.parse(rawData);
|
|
95
|
+
}
|
|
96
|
+
if (sub.streaming === 'sse') {
|
|
97
|
+
for await (const event of client.requestStream({ method: sub.method, path: sub.path, pathParams, queryParams, body, verbose })) {
|
|
98
|
+
console.log(event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
(0, output_1.formatOutput)(await client.request({ method: sub.method, path: sub.path, pathParams, queryParams, body, verbose, allPages }), format, query);
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Build body from individual field options
|
|
107
|
+
const bodyObj = {};
|
|
108
|
+
if (sub.requestBody) {
|
|
109
|
+
for (const field of sub.requestBody.fields) {
|
|
110
|
+
const val = opts[field.optKey];
|
|
111
|
+
if (val !== undefined)
|
|
112
|
+
bodyObj[field.name] = val;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const body = Object.keys(bodyObj).length > 0 ? bodyObj : undefined;
|
|
116
|
+
if (sub.streaming === 'sse') {
|
|
117
|
+
for await (const event of client.requestStream({ method: sub.method, path: sub.path, pathParams, queryParams, body, verbose })) {
|
|
118
|
+
console.log(event);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
(0, output_1.formatOutput)(await client.request({ method: sub.method, path: sub.path, pathParams, queryParams, body, verbose, allPages }), format, query);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Register one operation as a Commander subcommand on `parent`.
|
|
126
|
+
function registerOperation(parent, sub, client) {
|
|
127
|
+
const cmd = new commander_1.Command(sub.name).description(sub.description);
|
|
128
|
+
for (const alias of sub.aliases ?? []) {
|
|
129
|
+
cmd.alias(alias);
|
|
130
|
+
}
|
|
131
|
+
// Operation-specific options (parameters + body fields + --data)
|
|
132
|
+
for (const opt of sub.options) {
|
|
133
|
+
const flag = opt.type === 'boolean'
|
|
134
|
+
? `--${opt.name}`
|
|
135
|
+
: `--${opt.name} <value>`;
|
|
136
|
+
const co = new commander_1.Option(flag, opt.description);
|
|
137
|
+
if (opt.enum)
|
|
138
|
+
co.choices(opt.enum);
|
|
139
|
+
if (opt.defaultValue !== undefined)
|
|
140
|
+
co.default(opt.defaultValue);
|
|
141
|
+
cmd.addOption(co);
|
|
142
|
+
}
|
|
143
|
+
// Per-call output options (match generated CLI behaviour)
|
|
144
|
+
cmd.option('--format <format>', 'Output format: json, yaml, table', 'json');
|
|
145
|
+
cmd.option('--verbose', 'Log HTTP method and URL to stderr', false);
|
|
146
|
+
cmd.option('--query <expr>', 'JMESPath expression to filter the response');
|
|
147
|
+
cmd.option('--all-pages', 'Auto-paginate via Link rel="next" headers', false);
|
|
148
|
+
cmd.action(async (opts) => {
|
|
149
|
+
try {
|
|
150
|
+
await executeOperation(sub, opts, client);
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
const axiosErr = err;
|
|
154
|
+
if (axiosErr.response) {
|
|
155
|
+
console.error(chalk_1.default.red(`HTTP ${axiosErr.response.status}:`), axiosErr.response.statusText);
|
|
156
|
+
if (axiosErr.response.data) {
|
|
157
|
+
console.error(chalk_1.default.dim(JSON.stringify(axiosErr.response.data, null, 2)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.error(chalk_1.default.red('Error:'), err.message);
|
|
162
|
+
}
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
parent.addCommand(cmd);
|
|
167
|
+
}
|
|
168
|
+
// Build a Commander program with all operations from the analyzed structure.
|
|
169
|
+
function buildOperationsProgram(structure, client) {
|
|
170
|
+
const prog = new commander_1.Command()
|
|
171
|
+
.name('run')
|
|
172
|
+
.description(structure.description || `API proxy for OpenAPI spec`);
|
|
173
|
+
// Suppress Commander's default error exit so we can handle unknown commands gracefully
|
|
174
|
+
prog.exitOverride();
|
|
175
|
+
for (const group of structure.groups) {
|
|
176
|
+
const groupCmd = new commander_1.Command(group.name)
|
|
177
|
+
.description(group.description)
|
|
178
|
+
.exitOverride();
|
|
179
|
+
for (const sub of group.subcommands) {
|
|
180
|
+
registerOperation(groupCmd, sub, client);
|
|
181
|
+
}
|
|
182
|
+
prog.addCommand(groupCmd);
|
|
183
|
+
}
|
|
184
|
+
for (const sub of structure.flatCommands) {
|
|
185
|
+
registerOperation(prog, sub, client);
|
|
186
|
+
}
|
|
187
|
+
return prog;
|
|
188
|
+
}
|
|
189
|
+
// Print a compact listing of all available operations.
|
|
190
|
+
function listOperations(structure) {
|
|
191
|
+
const title = structure.description || structure.name;
|
|
192
|
+
console.log(chalk_1.default.bold(title));
|
|
193
|
+
console.log('');
|
|
194
|
+
if (structure.groups.length === 0 && structure.flatCommands.length === 0) {
|
|
195
|
+
console.log(chalk_1.default.dim(' (no operations found in this spec)'));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
for (const group of structure.groups) {
|
|
199
|
+
console.log(chalk_1.default.cyan(` ${group.name}`) + chalk_1.default.dim(` — ${group.description}`));
|
|
200
|
+
for (const sub of group.subcommands) {
|
|
201
|
+
const method = chalk_1.default.dim(`[${sub.method.toUpperCase()}]`);
|
|
202
|
+
console.log(` ${chalk_1.default.bold(sub.name)} ${method} ${sub.description}`);
|
|
203
|
+
}
|
|
204
|
+
console.log('');
|
|
205
|
+
}
|
|
206
|
+
for (const sub of structure.flatCommands) {
|
|
207
|
+
const method = chalk_1.default.dim(`[${sub.method.toUpperCase()}]`);
|
|
208
|
+
console.log(` ${chalk_1.default.bold(sub.name)} ${method} ${sub.description}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Entry point called from the `run` subcommand in src/index.ts.
|
|
212
|
+
async function proxyRun(proxyOpts, remainingArgs) {
|
|
213
|
+
// Load and analyse the spec (name is irrelevant in proxy mode)
|
|
214
|
+
let api;
|
|
215
|
+
try {
|
|
216
|
+
api = await (0, oas_parser_1.parseOAS)(proxyOpts.oas);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
console.error(chalk_1.default.red('Failed to load spec:'), err.message);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
const structure = (0, schema_analyzer_1.analyzeSchema)(api, '_proxy_');
|
|
223
|
+
const baseURL = proxyOpts.endpoint ?? structure.baseUrl;
|
|
224
|
+
const auth = {
|
|
225
|
+
bearer: proxyOpts.bearer,
|
|
226
|
+
apiKey: proxyOpts.apiKey,
|
|
227
|
+
apiKeyHeader: proxyOpts.apiKeyHeader,
|
|
228
|
+
basic: proxyOpts.basic,
|
|
229
|
+
extraHeaders: parseExtraHeaders(proxyOpts.header),
|
|
230
|
+
};
|
|
231
|
+
const client = (0, http_client_1.createRuntimeClient)(baseURL, auth);
|
|
232
|
+
// No operation given → show available commands
|
|
233
|
+
if (remainingArgs.length === 0) {
|
|
234
|
+
listOperations(structure);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const prog = buildOperationsProgram(structure, client);
|
|
238
|
+
try {
|
|
239
|
+
await prog.parseAsync(['node', 'run', ...remainingArgs]);
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
// exitOverride turns Commander errors into thrown exceptions
|
|
243
|
+
const cmdErr = err;
|
|
244
|
+
if (cmdErr.code === 'commander.unknownCommand') {
|
|
245
|
+
console.error(chalk_1.default.red('Unknown command:'), remainingArgs.join(' '));
|
|
246
|
+
console.error('Run without an operation to list available commands.');
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
if (cmdErr.code?.startsWith('commander.')) {
|
|
250
|
+
// Help display etc. — already printed by Commander
|
|
251
|
+
process.exit(0);
|
|
252
|
+
}
|
|
253
|
+
throw err;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=proxy-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-runner.js","sourceRoot":"","sources":["../../src/runner/proxy-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+MA,4BAgDC;AA/PD,yCAA+D;AAC/D,kDAA0B;AAC1B,oDAAuB;AACvB,8CAAgC;AAChC,2CAA6B;AAC7B,qDAAgD;AAChD,iEAA4D;AAE5D,+CAAiE;AACjE,qCAAwC;AAYxC,iDAAiD;AACjD,SAAS,iBAAiB,CAAC,OAA6B;IACtD,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,SAAS;QACzB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iFAAiF;AACjF,wDAAwD;AACxD,SAAS,OAAO,CAAC,QAAgB;IAC/B,OAAO,gBAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAED,2DAA2D;AAC3D,KAAK,UAAU,gBAAgB,CAC7B,GAAe,EACf,IAA6B,EAC7B,MAA8C;IAE9C,MAAM,OAAO,GAAI,IAAI,CAAC,SAAS,CAAyB,IAAI,KAAK,CAAC;IAClE,MAAM,MAAM,GAAI,IAAI,CAAC,QAAQ,CAAwB,IAAI,MAAM,CAAC;IAChE,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;QACb,6DAA6D;QAC7D,MAAM,MAAM,GAAG,GAA0C,CAAC;QAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;YAC/C,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACtE,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1C,mDAAmD;YACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tronsfey/openapi2cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Generate a
|
|
3
|
+
"version": "1.0.11",
|
|
4
|
+
"description": "Generate or proxy any OpenAPI 3.x spec as a typed Commander.js CLI, with shell completion",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"openapi2cli": "./bin/openapi2cli"
|
|
@@ -42,34 +42,41 @@
|
|
|
42
42
|
"start": "node dist/index.js",
|
|
43
43
|
"test": "jest --testPathIgnorePatterns=tests/integration",
|
|
44
44
|
"test:e2e": "jest tests/integration/express-server.test.ts --testTimeout=180000",
|
|
45
|
+
"test:proxy-e2e": "jest tests/integration/proxy-e2e.test.ts --testTimeout=180000",
|
|
45
46
|
"test:integration": "jest tests/integration/github.test.ts --testTimeout=180000",
|
|
46
47
|
"test:all": "jest --testTimeout=180000",
|
|
47
48
|
"generate:examples": "ts-node scripts/generate-example.ts",
|
|
48
49
|
"test:coverage": "jest --coverage --testPathIgnorePatterns=tests/integration",
|
|
49
50
|
"lint": "tsc --noEmit",
|
|
50
51
|
"clean": "rm -rf dist",
|
|
51
|
-
"prepublishOnly": "npm run lint && npm test && npm run build && npm run generate:examples && npm run test:e2e"
|
|
52
|
+
"prepublishOnly": "npm run lint && npm test && npm run build && npm run generate:examples && npm run test:e2e && npm run test:proxy-e2e"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
55
56
|
"axios": "^1.7.9",
|
|
56
57
|
"chalk": "^4.1.2",
|
|
57
58
|
"commander": "^12.1.0",
|
|
59
|
+
"eventsource-parser": "^3.0.6",
|
|
58
60
|
"fs-extra": "^11.2.0",
|
|
59
61
|
"handlebars": "^4.7.8",
|
|
62
|
+
"jmespath": "^0.16.0",
|
|
60
63
|
"lodash": "^4.17.23",
|
|
61
64
|
"openapi-types": "^12.1.3",
|
|
62
65
|
"ora": "^5.4.1",
|
|
63
|
-
"pinyin-pro": "^3.28.0"
|
|
66
|
+
"pinyin-pro": "^3.28.0",
|
|
67
|
+
"yaml": "^2.8.3"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
70
|
+
"@types/axios-mock-adapter": "^1.9.0",
|
|
66
71
|
"@types/express": "^4.17.21",
|
|
67
72
|
"@types/fs-extra": "^11.0.4",
|
|
68
|
-
"express": "^4.21.2",
|
|
69
73
|
"@types/jest": "^29.5.14",
|
|
74
|
+
"@types/jmespath": "^0.15.2",
|
|
70
75
|
"@types/lodash": "^4.17.16",
|
|
71
76
|
"@types/node": "^22.0.0",
|
|
77
|
+
"axios-mock-adapter": "^2.1.0",
|
|
72
78
|
"copyfiles": "^2.4.1",
|
|
79
|
+
"express": "^4.21.2",
|
|
73
80
|
"jest": "^29.7.0",
|
|
74
81
|
"ts-jest": "^29.4.0",
|
|
75
82
|
"ts-node": "^10.9.2",
|