openapi-cli-gen 0.0.1__tar.gz
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.
- openapi_cli_gen-0.0.1/LICENSE +21 -0
- openapi_cli_gen-0.0.1/PKG-INFO +259 -0
- openapi_cli_gen-0.0.1/README.md +219 -0
- openapi_cli_gen-0.0.1/docs/specs/2026-04-08-openapi-cli-gen-design.md +488 -0
- openapi_cli_gen-0.0.1/docs/superpowers/plans/2026-04-09-openapi-cli-gen-v01.md +2035 -0
- openapi_cli_gen-0.0.1/experiments/EXPERIMENTS.md +279 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/01_pydantic_settings_tree.py +193 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/01b_manual_dispatch.py +255 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/01c_typer_tree.py +196 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/01d_typer_from_pydantic.py +338 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/02_nested_flattening.py +134 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/03_arrays.py +178 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/06_spec_parsing.py +182 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/07_model_generation.py +160 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/08_end_to_end.py +374 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/09_unions.py +104 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/10_nullable.py +84 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/11_env_vars.py +101 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/12_output_formatting.py +133 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/13_dynamic_nested_models.py +149 -0
- openapi_cli_gen-0.0.1/experiments/prototypes/14_large_spec_performance.py +154 -0
- openapi_cli_gen-0.0.1/experiments/server/app.py +198 -0
- openapi_cli_gen-0.0.1/experiments/server/spec.yaml +547 -0
- openapi_cli_gen-0.0.1/pyproject.toml +57 -0
- openapi_cli_gen-0.0.1/research/architecture-references.md +90 -0
- openapi_cli_gen-0.0.1/research/competitive-landscape.md +45 -0
- openapi_cli_gen-0.0.1/research/pydantic-settings-cli-details.md +73 -0
- openapi_cli_gen-0.0.1/research/stainless-design-patterns.md +76 -0
- openapi_cli_gen-0.0.1/research/technical-stack.md +110 -0
- openapi_cli_gen-0.0.1/research/user-research.md +79 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/__init__.py +7 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/__main__.py +3 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/cli.py +70 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/codegen/__init__.py +0 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/codegen/generator.py +42 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/codegen/templates/__init__.py.jinja2 +1 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/codegen/templates/cli.py.jinja2 +15 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/codegen/templates/pyproject.toml.jinja2 +15 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/__init__.py +0 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/auth.py +52 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/builder.py +127 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/dispatch.py +62 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/models.py +117 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/engine/registry.py +119 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/output/__init__.py +0 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/output/formatter.py +66 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/spec/__init__.py +0 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/spec/loader.py +34 -0
- openapi_cli_gen-0.0.1/src/openapi_cli_gen/spec/parser.py +104 -0
- openapi_cli_gen-0.0.1/tests/__init__.py +0 -0
- openapi_cli_gen-0.0.1/tests/conftest.py +21 -0
- openapi_cli_gen-0.0.1/tests/test_auth.py +41 -0
- openapi_cli_gen-0.0.1/tests/test_cli.py +30 -0
- openapi_cli_gen-0.0.1/tests/test_codegen.py +35 -0
- openapi_cli_gen-0.0.1/tests/test_dispatch.py +37 -0
- openapi_cli_gen-0.0.1/tests/test_formatter.py +43 -0
- openapi_cli_gen-0.0.1/tests/test_integration.py +66 -0
- openapi_cli_gen-0.0.1/tests/test_loader.py +32 -0
- openapi_cli_gen-0.0.1/tests/test_models.py +120 -0
- openapi_cli_gen-0.0.1/tests/test_parser.py +67 -0
- openapi_cli_gen-0.0.1/tests/test_registry.py +45 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openapi-cli-gen contributors
|
|
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.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openapi-cli-gen
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Generate typed Python CLIs from OpenAPI specs with Pydantic model flattening into CLI flags
|
|
5
|
+
Project-URL: Homepage, https://github.com/shivaam/openapi-cli-gen
|
|
6
|
+
Project-URL: Repository, https://github.com/shivaam/openapi-cli-gen
|
|
7
|
+
Project-URL: Issues, https://github.com/shivaam/openapi-cli-gen/issues
|
|
8
|
+
Author: shivaam
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: cli,code-generator,fastapi,openapi,pydantic,typer
|
|
12
|
+
Classifier: Development Status :: 1 - Planning
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Requires-Dist: jinja2>=3.1
|
|
25
|
+
Requires-Dist: jsonref>=1.1
|
|
26
|
+
Requires-Dist: openapi-pydantic>=0.5
|
|
27
|
+
Requires-Dist: pydantic-settings>=2.13
|
|
28
|
+
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Requires-Dist: rich>=13.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: datamodel-code-generator>=0.56; extra == 'dev'
|
|
32
|
+
Requires-Dist: fastapi>=0.115; extra == 'dev'
|
|
33
|
+
Requires-Dist: jinja2>=3.1; extra == 'dev'
|
|
34
|
+
Requires-Dist: pydanclick>=0.5; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
37
|
+
Requires-Dist: typer>=0.12; extra == 'dev'
|
|
38
|
+
Requires-Dist: uvicorn>=0.30; extra == 'dev'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# openapi-cli-gen
|
|
42
|
+
|
|
43
|
+
**Generate a full CLI from any OpenAPI spec in seconds. Nested request bodies become flat `--flags` automatically.**
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/openapi-cli-gen/)
|
|
46
|
+
[](https://pypi.org/project/openapi-cli-gen/)
|
|
47
|
+
[](https://opensource.org/licenses/MIT)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Instead of this:
|
|
51
|
+
curl -X POST /api/users -d '{"name": "John", "address": {"city": "NYC", "state": "NY"}}'
|
|
52
|
+
|
|
53
|
+
# You get this:
|
|
54
|
+
mycli users create --name John --address.city NYC --address.state NY
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
No tool existed to take an OpenAPI spec and produce a typed Python CLI where nested request bodies are flattened into individual `--flag` arguments. Until now.
|
|
58
|
+
|
|
59
|
+
## Why openapi-cli-gen?
|
|
60
|
+
|
|
61
|
+
- **Zero boilerplate** -- point at a spec, get a working CLI
|
|
62
|
+
- **Nested model flattening** -- `--address.city NYC` not `--data '{"address":{"city":"NYC"}}'`
|
|
63
|
+
- **Works at any depth** -- 1, 2, 3+ levels of nesting with automatic dot-notation
|
|
64
|
+
- **Arrays, dicts, enums** -- all handled (`--tags dev --tags lead`, `--env KEY=val`, `--role {admin,user}`)
|
|
65
|
+
- **Auth from your spec** -- reads `securitySchemes`, wires up `--token` + env vars automatically
|
|
66
|
+
- **Two modes** -- generate a pip-installable package OR run instantly without code generation
|
|
67
|
+
- **Pluggable** -- use standalone or plug API commands into your existing CLI
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install openapi-cli-gen
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Generate a CLI Package
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
openapi-cli-gen generate --spec https://api.example.com/openapi.json --name mycli
|
|
79
|
+
cd mycli && pip install -e .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Now your users can:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
mycli users list
|
|
86
|
+
mycli users create --name John --email john@example.com --address.city NYC
|
|
87
|
+
mycli jobs create --retry.backoff.strategy exponential --retry.backoff.initial-delay-ms 2000
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Run Instantly (No Code Generation)
|
|
91
|
+
|
|
92
|
+
Don't want to generate files? Point directly at any spec:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
openapi-cli-gen run --spec api.yaml users list --limit 10
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Inspect a Spec
|
|
99
|
+
|
|
100
|
+
See what commands would be generated before committing:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
$ openapi-cli-gen inspect --spec api.yaml
|
|
104
|
+
|
|
105
|
+
API: My API v1.0
|
|
106
|
+
Endpoints: 14
|
|
107
|
+
Groups: 6
|
|
108
|
+
Auth schemes: 2
|
|
109
|
+
|
|
110
|
+
users:
|
|
111
|
+
GET /users List all users
|
|
112
|
+
POST /users Create a new user [body]
|
|
113
|
+
GET /users/{user_id} Get a user by ID
|
|
114
|
+
orders:
|
|
115
|
+
POST /orders Create an order [body]
|
|
116
|
+
...
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## The Core Feature: Nested Model Flattening
|
|
120
|
+
|
|
121
|
+
This is what makes openapi-cli-gen different from every other tool. Your API has nested request bodies -- we flatten them into ergonomic CLI flags:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Depth 1: address nested inside user
|
|
125
|
+
mycli users create --name John --address.city NYC --address.state NY
|
|
126
|
+
|
|
127
|
+
# Depth 2: CEO nested inside company
|
|
128
|
+
mycli companies create --name Acme --ceo.name Bob --ceo.email bob@acme.com
|
|
129
|
+
|
|
130
|
+
# Depth 3: backoff nested inside retry nested inside job config
|
|
131
|
+
mycli jobs create --name etl --retry.backoff.strategy exponential --retry.backoff.initial-delay-ms 2000
|
|
132
|
+
|
|
133
|
+
# JSON fallback for anything complex
|
|
134
|
+
mycli users create --address '{"street": "123 Main", "city": "NYC"}'
|
|
135
|
+
|
|
136
|
+
# Mix both -- dot-notation overrides JSON
|
|
137
|
+
mycli users create --address '{"city": "NYC"}' --address.city SF # city=SF wins
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Arrays
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Repeated flags for primitives
|
|
144
|
+
mycli users create --tags admin --tags reviewer
|
|
145
|
+
# Or comma-separated
|
|
146
|
+
mycli users create --tags admin,reviewer
|
|
147
|
+
# Or JSON
|
|
148
|
+
mycli users create --tags '["admin", "reviewer"]'
|
|
149
|
+
|
|
150
|
+
# JSON for arrays of objects
|
|
151
|
+
mycli orders create --items '[{"product_id": "abc", "quantity": 2}]'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Dicts
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Key=value syntax
|
|
158
|
+
mycli jobs create --environment JAVA_HOME=/usr/lib/jvm --environment PATH=/usr/bin
|
|
159
|
+
# Or JSON
|
|
160
|
+
mycli jobs create --environment '{"JAVA_HOME": "/usr/lib/jvm"}'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Enums
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
mycli users create --role admin # choices shown in --help: {admin, user, viewer}
|
|
167
|
+
mycli users create --role superadmin # ValidationError: Input should be 'admin', 'user' or 'viewer'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## As a Library
|
|
171
|
+
|
|
172
|
+
### Build a full CLI from a spec
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from openapi_cli_gen import build_cli
|
|
176
|
+
|
|
177
|
+
app = build_cli(spec="openapi.yaml", name="mycli")
|
|
178
|
+
app()
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Plug API commands into your existing CLI
|
|
182
|
+
|
|
183
|
+
Already have a CLI with custom commands? Add auto-generated API commands alongside them:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from openapi_cli_gen import build_command_group
|
|
187
|
+
|
|
188
|
+
# Returns {group: {command: CommandInfo}}
|
|
189
|
+
registry = build_command_group(spec="openapi.yaml", name="mycli")
|
|
190
|
+
# Integrate with your existing argparse-based CLI
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Authentication
|
|
194
|
+
|
|
195
|
+
Auth auto-configures from your spec's `securitySchemes`:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Via environment variable (recommended for CI/CD)
|
|
199
|
+
export MYCLI_TOKEN=sk-xxx
|
|
200
|
+
mycli users list
|
|
201
|
+
|
|
202
|
+
# Via flag (overrides env var)
|
|
203
|
+
mycli users list --token sk-xxx
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
| Spec scheme | CLI flag | Env var |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| Bearer token | `--token` | `{NAME}_TOKEN` |
|
|
209
|
+
| API key | `--api-key` | `{NAME}_API_KEY` |
|
|
210
|
+
| Basic auth | `--username`, `--password` | `{NAME}_USERNAME`, `{NAME}_PASSWORD` |
|
|
211
|
+
|
|
212
|
+
## How It Works
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
Your OpenAPI spec (YAML/JSON)
|
|
216
|
+
|
|
|
217
|
+
v
|
|
218
|
+
1. Load & resolve all $ref references (jsonref)
|
|
219
|
+
2. Parse into typed models (openapi-pydantic)
|
|
220
|
+
3. Group endpoints by tag -> command groups
|
|
221
|
+
4. Flatten request body schemas into CLI flags (pydantic-settings)
|
|
222
|
+
5. Build CLI with dispatch: mycli <group> <command> --flags
|
|
223
|
+
|
|
|
224
|
+
v
|
|
225
|
+
Working CLI in seconds
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Compared to Alternatives
|
|
229
|
+
|
|
230
|
+
| Feature | openapi-cli-gen | specli | restish | Stainless |
|
|
231
|
+
|---|---|---|---|---|
|
|
232
|
+
| Language | Python | TypeScript | Go | Go |
|
|
233
|
+
| Generates distributable code | Yes | No | No | Yes |
|
|
234
|
+
| Runtime mode (no codegen) | Yes | Yes | Yes | No |
|
|
235
|
+
| Nested model flattening | All depths | Scalars only | No | 2 levels |
|
|
236
|
+
| Typed Pydantic models | Yes | No | No | N/A |
|
|
237
|
+
| Auth from spec | Yes | Partial | Manual | Yes |
|
|
238
|
+
| Pluggable into existing CLI | Yes | No | No | No |
|
|
239
|
+
| Open source | Yes | Yes | Yes | No |
|
|
240
|
+
|
|
241
|
+
## Supported
|
|
242
|
+
|
|
243
|
+
- OpenAPI 3.0 and 3.1
|
|
244
|
+
- All HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
245
|
+
- Local, external, and circular `$ref` resolution
|
|
246
|
+
- Path parameters, query parameters, request bodies
|
|
247
|
+
- Nested objects, arrays, dicts, enums, nullable fields
|
|
248
|
+
- Bearer token and API key authentication
|
|
249
|
+
- JSON, YAML, table (rich), and raw output formats
|
|
250
|
+
|
|
251
|
+
## Status
|
|
252
|
+
|
|
253
|
+
Early release (v0.0.1). Core features work. Roadmap includes Typer output target (rich `--help`, shell completion), auto-pagination, OAuth2, and more.
|
|
254
|
+
|
|
255
|
+
[Issues and feedback welcome.](https://github.com/shivaam/openapi-cli-gen/issues)
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# openapi-cli-gen
|
|
2
|
+
|
|
3
|
+
**Generate a full CLI from any OpenAPI spec in seconds. Nested request bodies become flat `--flags` automatically.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/openapi-cli-gen/)
|
|
6
|
+
[](https://pypi.org/project/openapi-cli-gen/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Instead of this:
|
|
11
|
+
curl -X POST /api/users -d '{"name": "John", "address": {"city": "NYC", "state": "NY"}}'
|
|
12
|
+
|
|
13
|
+
# You get this:
|
|
14
|
+
mycli users create --name John --address.city NYC --address.state NY
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
No tool existed to take an OpenAPI spec and produce a typed Python CLI where nested request bodies are flattened into individual `--flag` arguments. Until now.
|
|
18
|
+
|
|
19
|
+
## Why openapi-cli-gen?
|
|
20
|
+
|
|
21
|
+
- **Zero boilerplate** -- point at a spec, get a working CLI
|
|
22
|
+
- **Nested model flattening** -- `--address.city NYC` not `--data '{"address":{"city":"NYC"}}'`
|
|
23
|
+
- **Works at any depth** -- 1, 2, 3+ levels of nesting with automatic dot-notation
|
|
24
|
+
- **Arrays, dicts, enums** -- all handled (`--tags dev --tags lead`, `--env KEY=val`, `--role {admin,user}`)
|
|
25
|
+
- **Auth from your spec** -- reads `securitySchemes`, wires up `--token` + env vars automatically
|
|
26
|
+
- **Two modes** -- generate a pip-installable package OR run instantly without code generation
|
|
27
|
+
- **Pluggable** -- use standalone or plug API commands into your existing CLI
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install openapi-cli-gen
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Generate a CLI Package
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
openapi-cli-gen generate --spec https://api.example.com/openapi.json --name mycli
|
|
39
|
+
cd mycli && pip install -e .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Now your users can:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
mycli users list
|
|
46
|
+
mycli users create --name John --email john@example.com --address.city NYC
|
|
47
|
+
mycli jobs create --retry.backoff.strategy exponential --retry.backoff.initial-delay-ms 2000
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Run Instantly (No Code Generation)
|
|
51
|
+
|
|
52
|
+
Don't want to generate files? Point directly at any spec:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
openapi-cli-gen run --spec api.yaml users list --limit 10
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Inspect a Spec
|
|
59
|
+
|
|
60
|
+
See what commands would be generated before committing:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
$ openapi-cli-gen inspect --spec api.yaml
|
|
64
|
+
|
|
65
|
+
API: My API v1.0
|
|
66
|
+
Endpoints: 14
|
|
67
|
+
Groups: 6
|
|
68
|
+
Auth schemes: 2
|
|
69
|
+
|
|
70
|
+
users:
|
|
71
|
+
GET /users List all users
|
|
72
|
+
POST /users Create a new user [body]
|
|
73
|
+
GET /users/{user_id} Get a user by ID
|
|
74
|
+
orders:
|
|
75
|
+
POST /orders Create an order [body]
|
|
76
|
+
...
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## The Core Feature: Nested Model Flattening
|
|
80
|
+
|
|
81
|
+
This is what makes openapi-cli-gen different from every other tool. Your API has nested request bodies -- we flatten them into ergonomic CLI flags:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Depth 1: address nested inside user
|
|
85
|
+
mycli users create --name John --address.city NYC --address.state NY
|
|
86
|
+
|
|
87
|
+
# Depth 2: CEO nested inside company
|
|
88
|
+
mycli companies create --name Acme --ceo.name Bob --ceo.email bob@acme.com
|
|
89
|
+
|
|
90
|
+
# Depth 3: backoff nested inside retry nested inside job config
|
|
91
|
+
mycli jobs create --name etl --retry.backoff.strategy exponential --retry.backoff.initial-delay-ms 2000
|
|
92
|
+
|
|
93
|
+
# JSON fallback for anything complex
|
|
94
|
+
mycli users create --address '{"street": "123 Main", "city": "NYC"}'
|
|
95
|
+
|
|
96
|
+
# Mix both -- dot-notation overrides JSON
|
|
97
|
+
mycli users create --address '{"city": "NYC"}' --address.city SF # city=SF wins
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Arrays
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Repeated flags for primitives
|
|
104
|
+
mycli users create --tags admin --tags reviewer
|
|
105
|
+
# Or comma-separated
|
|
106
|
+
mycli users create --tags admin,reviewer
|
|
107
|
+
# Or JSON
|
|
108
|
+
mycli users create --tags '["admin", "reviewer"]'
|
|
109
|
+
|
|
110
|
+
# JSON for arrays of objects
|
|
111
|
+
mycli orders create --items '[{"product_id": "abc", "quantity": 2}]'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Dicts
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Key=value syntax
|
|
118
|
+
mycli jobs create --environment JAVA_HOME=/usr/lib/jvm --environment PATH=/usr/bin
|
|
119
|
+
# Or JSON
|
|
120
|
+
mycli jobs create --environment '{"JAVA_HOME": "/usr/lib/jvm"}'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Enums
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
mycli users create --role admin # choices shown in --help: {admin, user, viewer}
|
|
127
|
+
mycli users create --role superadmin # ValidationError: Input should be 'admin', 'user' or 'viewer'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## As a Library
|
|
131
|
+
|
|
132
|
+
### Build a full CLI from a spec
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from openapi_cli_gen import build_cli
|
|
136
|
+
|
|
137
|
+
app = build_cli(spec="openapi.yaml", name="mycli")
|
|
138
|
+
app()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Plug API commands into your existing CLI
|
|
142
|
+
|
|
143
|
+
Already have a CLI with custom commands? Add auto-generated API commands alongside them:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from openapi_cli_gen import build_command_group
|
|
147
|
+
|
|
148
|
+
# Returns {group: {command: CommandInfo}}
|
|
149
|
+
registry = build_command_group(spec="openapi.yaml", name="mycli")
|
|
150
|
+
# Integrate with your existing argparse-based CLI
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Authentication
|
|
154
|
+
|
|
155
|
+
Auth auto-configures from your spec's `securitySchemes`:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Via environment variable (recommended for CI/CD)
|
|
159
|
+
export MYCLI_TOKEN=sk-xxx
|
|
160
|
+
mycli users list
|
|
161
|
+
|
|
162
|
+
# Via flag (overrides env var)
|
|
163
|
+
mycli users list --token sk-xxx
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Spec scheme | CLI flag | Env var |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| Bearer token | `--token` | `{NAME}_TOKEN` |
|
|
169
|
+
| API key | `--api-key` | `{NAME}_API_KEY` |
|
|
170
|
+
| Basic auth | `--username`, `--password` | `{NAME}_USERNAME`, `{NAME}_PASSWORD` |
|
|
171
|
+
|
|
172
|
+
## How It Works
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
Your OpenAPI spec (YAML/JSON)
|
|
176
|
+
|
|
|
177
|
+
v
|
|
178
|
+
1. Load & resolve all $ref references (jsonref)
|
|
179
|
+
2. Parse into typed models (openapi-pydantic)
|
|
180
|
+
3. Group endpoints by tag -> command groups
|
|
181
|
+
4. Flatten request body schemas into CLI flags (pydantic-settings)
|
|
182
|
+
5. Build CLI with dispatch: mycli <group> <command> --flags
|
|
183
|
+
|
|
|
184
|
+
v
|
|
185
|
+
Working CLI in seconds
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Compared to Alternatives
|
|
189
|
+
|
|
190
|
+
| Feature | openapi-cli-gen | specli | restish | Stainless |
|
|
191
|
+
|---|---|---|---|---|
|
|
192
|
+
| Language | Python | TypeScript | Go | Go |
|
|
193
|
+
| Generates distributable code | Yes | No | No | Yes |
|
|
194
|
+
| Runtime mode (no codegen) | Yes | Yes | Yes | No |
|
|
195
|
+
| Nested model flattening | All depths | Scalars only | No | 2 levels |
|
|
196
|
+
| Typed Pydantic models | Yes | No | No | N/A |
|
|
197
|
+
| Auth from spec | Yes | Partial | Manual | Yes |
|
|
198
|
+
| Pluggable into existing CLI | Yes | No | No | No |
|
|
199
|
+
| Open source | Yes | Yes | Yes | No |
|
|
200
|
+
|
|
201
|
+
## Supported
|
|
202
|
+
|
|
203
|
+
- OpenAPI 3.0 and 3.1
|
|
204
|
+
- All HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
205
|
+
- Local, external, and circular `$ref` resolution
|
|
206
|
+
- Path parameters, query parameters, request bodies
|
|
207
|
+
- Nested objects, arrays, dicts, enums, nullable fields
|
|
208
|
+
- Bearer token and API key authentication
|
|
209
|
+
- JSON, YAML, table (rich), and raw output formats
|
|
210
|
+
|
|
211
|
+
## Status
|
|
212
|
+
|
|
213
|
+
Early release (v0.0.1). Core features work. Roadmap includes Typer output target (rich `--help`, shell completion), auto-pagination, OAuth2, and more.
|
|
214
|
+
|
|
215
|
+
[Issues and feedback welcome.](https://github.com/shivaam/openapi-cli-gen/issues)
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|