@tangcent/apilot 0.1.2 → 0.1.4
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/CHANGELOG.md +201 -93
- package/LICENSE +661 -661
- package/README.md +563 -220
- package/package.json +34 -34
- package/scripts/install.js +124 -124
- package/scripts/run.js +27 -27
package/README.md
CHANGED
|
@@ -1,220 +1,563 @@
|
|
|
1
|
-
# APilot
|
|
2
|
-
|
|
3
|
-
> Navigate your APIs. Automatically.
|
|
4
|
-
|
|
5
|
-
APilot scans your source code, extracts API endpoints, and exports them to the format you need — Postman collections, Markdown docs, cURL commands, and more. No annotations required, no runtime needed.
|
|
6
|
-
|
|
7
|
-
[](https://github.com/tangcent/apilot/actions/workflows/ci.yml)
|
|
8
|
-
[](https://www.npmjs.com/package/@tangcent/apilot)
|
|
10
|
-
[](LICENSE)
|
|
11
|
-
|
|
12
|
-
1 AI Agent [Skill](./skills/)
|
|
13
|
-
|
|
14
|
-
| Skill | Description |
|
|
15
|
-
|-------|-------------|
|
|
16
|
-
| `apilot` | Scan source code and export API endpoints to Postman, Markdown, cURL, and more |
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## What it does
|
|
21
|
-
|
|
22
|
-
Point APilot at a source directory and it figures out the rest:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
apilot export ./my-service --formatter postman --output collection.json
|
|
26
|
-
apilot export ./my-service --formatter markdown --format detailed
|
|
27
|
-
apilot export ./my-service --formatter curl
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
#
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
1
|
+
# APilot
|
|
2
|
+
|
|
3
|
+
> Navigate your APIs. Automatically.
|
|
4
|
+
|
|
5
|
+
APilot scans your source code, extracts API endpoints, and exports them to the format you need — Postman collections, Markdown docs, cURL commands, and more. No annotations required, no runtime needed.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/tangcent/apilot/actions/workflows/ci.yml)
|
|
8
|
+
[](https://codecov.io/gh/tangcent/apilot)
|
|
9
|
+
[](https://www.npmjs.com/package/@tangcent/apilot)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
1 AI Agent [Skill](./skills/)
|
|
13
|
+
|
|
14
|
+
| Skill | Description |
|
|
15
|
+
|-------|-------------|
|
|
16
|
+
| `apilot` | Scan source code and export API endpoints to Postman, Markdown, cURL, and more |
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## What it does
|
|
21
|
+
|
|
22
|
+
Point APilot at a source directory and it figures out the rest:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
apilot export ./my-service --formatter postman --output collection.json
|
|
26
|
+
apilot export ./my-service --formatter markdown --format detailed
|
|
27
|
+
apilot export ./my-service --formatter curl
|
|
28
|
+
apilot export ./my-service --formatter json --output api.json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
It detects your language and framework automatically, walks the source tree, and produces clean, structured API output — ready to import into Postman, share as docs, or drop into a CI pipeline.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Supported languages & frameworks
|
|
36
|
+
|
|
37
|
+
| Language | Frameworks |
|
|
38
|
+
|------------|-----------------------------------------|
|
|
39
|
+
| Java | Spring MVC, JAX-RS, Feign |
|
|
40
|
+
| Kotlin | Spring MVC |
|
|
41
|
+
| Go | Gin, Echo, Fiber |
|
|
42
|
+
| Node.js | Express, Fastify, NestJS |
|
|
43
|
+
| Python | FastAPI, Django REST, Flask |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Output formats
|
|
48
|
+
|
|
49
|
+
| Format | Description |
|
|
50
|
+
|----------|------------------------------------------|
|
|
51
|
+
| markdown | Markdown docs (simple or detailed) |
|
|
52
|
+
| curl | One `curl` command per endpoint |
|
|
53
|
+
| postman | Postman Collection v2.1 JSON |
|
|
54
|
+
| json | Machine-readable endpoint JSON for CI |
|
|
55
|
+
| yapi | Saves endpoints to a YApi project, or prints YApi import JSON |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Quick Start (AI Agent)
|
|
60
|
+
|
|
61
|
+
> The following steps are for AI Agents (Claude Code, Cursor, etc.).
|
|
62
|
+
|
|
63
|
+
**Step 1 — Install**
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Install CLI
|
|
67
|
+
npm install -g @tangcent/apilot
|
|
68
|
+
|
|
69
|
+
# Install CLI SKILL (required)
|
|
70
|
+
npx skills add tangcent/apilot -y -g
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Step 2 — Export APIs**
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Scan source code and export to Postman
|
|
77
|
+
apilot export ./my-service --formatter postman --output api.postman_collection.json
|
|
78
|
+
|
|
79
|
+
# Generate Markdown documentation
|
|
80
|
+
apilot export ./my-service --formatter markdown --format detailed --output API.md
|
|
81
|
+
|
|
82
|
+
# Generate cURL commands
|
|
83
|
+
apilot export ./my-service --formatter curl
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Step 3 — Verify**
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
apilot export --list-collectors
|
|
90
|
+
apilot export --list-formatters
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
### npm (recommended)
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install -g @tangcent/apilot
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Download binary
|
|
104
|
+
|
|
105
|
+
Grab the latest release for your platform from the [releases page](https://github.com/tangcent/apilot/releases):
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# macOS (Apple Silicon)
|
|
109
|
+
curl -L https://github.com/tangcent/apilot/releases/latest/download/apilot-darwin-arm64 -o apilot
|
|
110
|
+
chmod +x apilot && sudo mv apilot /usr/local/bin/
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Build from source
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/tangcent/apilot.git
|
|
117
|
+
cd apilot
|
|
118
|
+
go build -o apilot ./apilot-cli
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Install from source (local development)
|
|
122
|
+
|
|
123
|
+
Use the install script to build and install `apilot` to your local PATH — handy for testing changes before release:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Clone and enter the repo
|
|
127
|
+
git clone https://github.com/tangcent/apilot.git
|
|
128
|
+
cd apilot
|
|
129
|
+
|
|
130
|
+
# Build and install to /usr/local/bin (or ~/.local/bin if no write access)
|
|
131
|
+
./scripts/install-local.sh
|
|
132
|
+
|
|
133
|
+
# Or specify a custom install directory
|
|
134
|
+
./scripts/install-local.sh /usr/local/bin
|
|
135
|
+
|
|
136
|
+
# Verify
|
|
137
|
+
apilot --version
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
After making code changes, just re-run `./scripts/install-local.sh` to rebuild and reinstall.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Usage
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
apilot export <source-path> [flags]
|
|
148
|
+
|
|
149
|
+
source-path can be a directory, or one or more source files.
|
|
150
|
+
When files are given, the project root is auto-detected by walking up
|
|
151
|
+
to find pom.xml, build.gradle, go.mod, package.json, etc.
|
|
152
|
+
For multi-module projects, the topmost aggregator is used: the directory
|
|
153
|
+
whose pom.xml lists the module, or that holds the settings.gradle(.kts)
|
|
154
|
+
of its Gradle build. A project that no build above lists keeps its own.
|
|
155
|
+
All files must belong to the same project; use --project-root otherwise.
|
|
156
|
+
|
|
157
|
+
Flags:
|
|
158
|
+
--collector string Collector name (auto-detected if omitted)
|
|
159
|
+
--formatter string Output format: markdown, curl, postman, json, yapi (default: markdown)
|
|
160
|
+
--format string Format variant, e.g. simple, detailed (default: simple)
|
|
161
|
+
--method string Filter to a specific method name (used with file-level export;
|
|
162
|
+
applies to every selected file)
|
|
163
|
+
--project-root string Override auto-detected project root directory
|
|
164
|
+
--no-deps Disable resolving request/response types from dependencies
|
|
165
|
+
--allow-empty Exit 0 when the collection yields no endpoints (default: fail)
|
|
166
|
+
--required-fields string How fields are marked required: default (unless @Nullable)
|
|
167
|
+
or constraints (only with @NotNull, @NotBlank, @NotEmpty)
|
|
168
|
+
--output string Output file path (default: stdout)
|
|
169
|
+
--list-collectors Print available collectors and exit
|
|
170
|
+
--list-formatters Print available formatters and exit
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Examples
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Export a Spring Boot project to Postman
|
|
177
|
+
apilot export ./backend --formatter postman --output api.postman_collection.json
|
|
178
|
+
|
|
179
|
+
# Generate detailed Markdown docs
|
|
180
|
+
apilot export ./backend --formatter markdown --format detailed --output API.md
|
|
181
|
+
|
|
182
|
+
# Quick cURL reference to stdout
|
|
183
|
+
apilot export ./backend --formatter curl
|
|
184
|
+
|
|
185
|
+
# Export all APIs from a specific file
|
|
186
|
+
apilot export UserController.java --formatter markdown
|
|
187
|
+
|
|
188
|
+
# Export several files of one project in one run
|
|
189
|
+
apilot export UserController.java OrderController.java --formatter markdown
|
|
190
|
+
|
|
191
|
+
# Export a single method from a file
|
|
192
|
+
apilot export UserController.java --method getUser --formatter curl
|
|
193
|
+
|
|
194
|
+
# Multi-module project: override project root
|
|
195
|
+
apilot export user-service/src/.../UserController.java --project-root ./company-platform
|
|
196
|
+
|
|
197
|
+
# Machine-readable export for a CI gate
|
|
198
|
+
apilot export ./backend --formatter json --output api.json
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Dependency type resolution
|
|
202
|
+
|
|
203
|
+
Beyond the project's own sources, APilot expands request and response types
|
|
204
|
+
that are declared in your dependencies — a shared common module, a third-party
|
|
205
|
+
library, a framework base class. Each language reaches those types through its
|
|
206
|
+
own environment:
|
|
207
|
+
|
|
208
|
+
| Language | Prerequisite | What happens without it |
|
|
209
|
+
|----------|--------------|--------------------------|
|
|
210
|
+
| Java, Kotlin | [`maven-indexer-cli`](https://github.com/tangcent/maven-indexer-mcp) on PATH (`npm install -g maven-indexer-cli`); 1.2.0 or later to read types at the project's versions (full pinning needs maven-indexer-mcp#28) | Resolution is skipped; a warning names the tool and the number of declared dependencies affected |
|
|
211
|
+
| Go | `go` toolchain on PATH (reads the module cache) | Resolution is skipped; a warning names the missing toolchain |
|
|
212
|
+
| Node.js | `npm install` run (reads `node_modules`) | Resolution is skipped; a warning says to install first |
|
|
213
|
+
| Python | A discoverable environment: project `.venv`/`venv`/`env`, `CONDA_PREFIX`, or `python` on PATH | Resolution is skipped; a warning says which environment to activate |
|
|
214
|
+
|
|
215
|
+
When resolution runs, APilot reports how many types were expanded from
|
|
216
|
+
dependencies (`info: resolved N types from dependencies`). Use `--no-deps` to
|
|
217
|
+
turn the capability off explicitly — useful in CI where the prerequisite is
|
|
218
|
+
known to be absent.
|
|
219
|
+
|
|
220
|
+
For Java and Kotlin, a class from a library written in Kotlin is read from its
|
|
221
|
+
Kotlin sources; a class without a sources JAR, such as a locally built
|
|
222
|
+
SNAPSHOT, is decompiled.
|
|
223
|
+
|
|
224
|
+
A library class is found by the name the source gives it: a single-type import,
|
|
225
|
+
the package of the source, or an import-on-demand (`import com.example.model.*`).
|
|
226
|
+
Each qualified name that the package of the source or an import-on-demand could
|
|
227
|
+
give an unimported name is asked of the indexer once, the package of the source
|
|
228
|
+
first and then the imports in the order they are written. A package that the
|
|
229
|
+
project's own sources declare is not asked, so a library class that sits in a
|
|
230
|
+
package of the project is not found by its simple name from a source of the
|
|
231
|
+
project (it can still be written in full). Which class a simple name denotes
|
|
232
|
+
follows the scope of the source, tier by tier, whatever the class comes from: a
|
|
233
|
+
class declared in the same file, a single-type import, the package of the source,
|
|
234
|
+
then the imports on demand. A class of the project that the source reaches by none
|
|
235
|
+
of these answers only when no tier does, and never for a class read from a library:
|
|
236
|
+
the library was built without the project, so a name it writes that no tier
|
|
237
|
+
declares stays unresolved.
|
|
238
|
+
|
|
239
|
+
A class nested in another is a class of its own, known by the classes it is
|
|
240
|
+
nested in: `Order.Item` and `Cart.Item` are two classes. Inside `Order`, and in
|
|
241
|
+
a class nested in it or one that extends it, a bare `Item` is the `Item` nested
|
|
242
|
+
in `Order`; elsewhere it is named `Order.Item`, by an import of
|
|
243
|
+
`com.example.Order.Item`, or by `import com.example.Order.*`. A bare name that no
|
|
244
|
+
scope declares is not guessed between two nested classes of that name, and it
|
|
245
|
+
is reported as unresolved. The indexer holds top-level classes only, so a class
|
|
246
|
+
nested in a library class is read from the source of the class that declares
|
|
247
|
+
it, in one call for the class and all that is nested in it.
|
|
248
|
+
|
|
249
|
+
A name written with a `$` is read as the binary name of a nested class
|
|
250
|
+
(`Outer$Inner`) and, when that finds no class, as the name of a class that has a
|
|
251
|
+
`$` in it (`Price$Value`); the indexer is asked for it as written, so it can say
|
|
252
|
+
which. A superclass is read like any other class, a library's included, whether it
|
|
253
|
+
is imported, imported on demand, a neighbour in the package or written in full, and
|
|
254
|
+
the arguments of its `extends` clause are read in the header of the subclass, where
|
|
255
|
+
the subclass's own nested classes are not in scope.
|
|
256
|
+
|
|
257
|
+
With maven-indexer-cli 1.2.0 or later, APilot asks the indexer to pin each
|
|
258
|
+
class to the version the project's dependency tree names (`--project-path`),
|
|
259
|
+
but on released CLIs up to 1.2.1 most types are still read from the version
|
|
260
|
+
the index holds and are reported as unpinned. It asks the indexer for the
|
|
261
|
+
project's dependency tree first: the indexer runs
|
|
262
|
+
`mvn dependency:tree` (or `gradle dependencies`) once and caches the result per
|
|
263
|
+
build file, so the first export of a project takes as long as that command, and
|
|
264
|
+
later ones do not. An older CLI still resolves types, from the version the
|
|
265
|
+
index holds, and a warning says so.
|
|
266
|
+
|
|
267
|
+
Whenever a type may come from a version other than the project's, a warning
|
|
268
|
+
says why: the tree could not be resolved, or the version it names is not
|
|
269
|
+
indexed. Types the indexer reports reading from another version are listed
|
|
270
|
+
with the version each was read from, and a lookup that fails is listed with
|
|
271
|
+
the reason. Up to maven-indexer-cli 1.2.1, the indexer pins only the classes
|
|
272
|
+
of the first artifact of the tree it has indexed, which is often the project
|
|
273
|
+
itself ([maven-indexer-mcp#28](https://github.com/tangcent/maven-indexer-mcp/pull/28));
|
|
274
|
+
the other classes are read from the version the index holds and listed in
|
|
275
|
+
that warning.
|
|
276
|
+
|
|
277
|
+
The indexer's default index keeps one version per artifact. To read the exact
|
|
278
|
+
versions your projects use, index all versions of your own libraries into an
|
|
279
|
+
index of their own, which is fast because the scope is small. The indexer reads
|
|
280
|
+
both variables from the environment, so keep them set when you run
|
|
281
|
+
`apilot export`:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
export DB_FILE="$HOME/.maven-indexer-mcp/my-libraries.sqlite"
|
|
285
|
+
export INCLUDED_PACKAGES='com.example.*'
|
|
286
|
+
maven-indexer-cli refresh-index --full
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
apilot export ./backend --formatter markdown --no-deps
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Required fields
|
|
294
|
+
|
|
295
|
+
Java and Kotlin fields are marked required in one of two ways:
|
|
296
|
+
|
|
297
|
+
| Mode | A field is required when | Use it when |
|
|
298
|
+
|------|--------------------------|-------------|
|
|
299
|
+
| `default` | it is not annotated `@Nullable` or `@Null` | fields are present unless declared otherwise |
|
|
300
|
+
| `constraints` | it carries `@NotNull`, `@NotBlank` or `@NotEmpty` | requests are validated with Bean Validation, so a field without a constraint may be left out |
|
|
301
|
+
|
|
302
|
+
`@Nullable` wins in both modes, and a `required` flag written in `@Schema` or
|
|
303
|
+
`@ApiModelProperty` overrides either. The `constraints` mode matches what the
|
|
304
|
+
validator enforces at runtime and how the EasyYapi IntelliJ plugin documents
|
|
305
|
+
fields.
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
apilot export ./backend --formatter json --required-fields constraints
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Empty exports
|
|
312
|
+
|
|
313
|
+
A run that yields no endpoints fails instead of writing a document that holds
|
|
314
|
+
only its heading. The failure names the collector and the path it looked at, so
|
|
315
|
+
an unsupported framework or a filter that matched nothing is visible rather than
|
|
316
|
+
silent:
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
endpoints: 0
|
|
320
|
+
error: collector "java" extracted 0 endpoints from "./backend" (pass --allow-empty to export an empty document)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Every run reports the exported endpoint count on stderr, so a pipeline can assert
|
|
324
|
+
the number from logs alone:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
apilot export ./backend --output API.md 2>&1 | grep -qx 'endpoints: 244'
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
When an empty document is the intended result — a service that legitimately has
|
|
331
|
+
no endpoints yet — pass `--allow-empty` to keep the run at exit 0.
|
|
332
|
+
|
|
333
|
+
### Three levels of granularity
|
|
334
|
+
|
|
335
|
+
| Command | Scope |
|
|
336
|
+
|---------|-------|
|
|
337
|
+
| `apilot export ./project` | All APIs in project |
|
|
338
|
+
| `apilot export UserController.java` | All APIs in that file |
|
|
339
|
+
| `apilot export UserController.java OrderController.java` | All APIs in those files |
|
|
340
|
+
| `apilot export UserController.java --method getUser` | One specific API |
|
|
341
|
+
|
|
342
|
+
The whole project is read for the types the selected files refer to, but
|
|
343
|
+
endpoints are built, and dependency types looked up, only for the controllers
|
|
344
|
+
the selected files declare. The Java and Kotlin collectors work this way, so
|
|
345
|
+
exporting a few controllers of a large service costs far less than exporting the
|
|
346
|
+
service. Naming the files in one run reads the project, and sets up the
|
|
347
|
+
dependency lookups, once, where one run per file would repeat both. The
|
|
348
|
+
document holds the endpoints in the order of a directory export, whatever the
|
|
349
|
+
order of the arguments.
|
|
350
|
+
|
|
351
|
+
The files must belong to one project. The project root of a file starts at the
|
|
352
|
+
nearest directory with a build file and climbs while the build above declares
|
|
353
|
+
that directory as one of its modules, up to the topmost aggregator:
|
|
354
|
+
|
|
355
|
+
- **Maven**: a `pom.xml` whose `<modules>`, in the project or in a profile, lists
|
|
356
|
+
the directory. A module path may be nested (`services/user`) or climb
|
|
357
|
+
(`../user`). The pom is looked for in every ancestor and in the place the
|
|
358
|
+
module's `<parent><relativePath>` names.
|
|
359
|
+
- **Gradle**: the nearest `settings.gradle` or `settings.gradle.kts` at or above
|
|
360
|
+
the directory, as Gradle itself finds the root of a build. The directory that
|
|
361
|
+
holds it must also have a `build.gradle(.kts)`. The `include` statements are
|
|
362
|
+
not read.
|
|
363
|
+
|
|
364
|
+
The controllers of every module of a repository then share one root, so the
|
|
365
|
+
types they take from their sibling modules are read from the sources instead of
|
|
366
|
+
being looked up in the dependency index, and files of different modules can be
|
|
367
|
+
exported in one run. A project that no build above lists keeps its nearest
|
|
368
|
+
directory as its root. When files still belong to different projects, or the
|
|
369
|
+
detected root is not the one wanted, name it with `--project-root`.
|
|
370
|
+
`--method` applies to every selected file.
|
|
371
|
+
|
|
372
|
+
### Machine-readable JSON
|
|
373
|
+
|
|
374
|
+
`--formatter json` writes one document a pipeline can diff and gate on, instead
|
|
375
|
+
of counting headings in markdown:
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
apilot export ./backend --formatter json --output api.json
|
|
379
|
+
apilot export ./backend --formatter json | jq '.endpoints | length'
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
The output depends only on the collected endpoints — no timestamps, no absolute
|
|
383
|
+
paths, no host-specific values — so the same input produces byte-identical
|
|
384
|
+
output on every machine, and endpoints are sorted rather than left in whatever
|
|
385
|
+
order the source tree was walked.
|
|
386
|
+
|
|
387
|
+
```json
|
|
388
|
+
{
|
|
389
|
+
"endpoints": [
|
|
390
|
+
{
|
|
391
|
+
"name": "getUser",
|
|
392
|
+
"method": "GET",
|
|
393
|
+
"path": "/users/:id",
|
|
394
|
+
"protocol": "http",
|
|
395
|
+
"description": "Returns a single user.",
|
|
396
|
+
"folder": "UserController",
|
|
397
|
+
"request": {
|
|
398
|
+
"parameters": {
|
|
399
|
+
"path": [
|
|
400
|
+
{ "name": "id", "type": "text", "required": true }
|
|
401
|
+
],
|
|
402
|
+
"query": [
|
|
403
|
+
{ "name": "verbose", "type": "text", "required": false, "default": "false" }
|
|
404
|
+
]
|
|
405
|
+
},
|
|
406
|
+
"body": {
|
|
407
|
+
"mediaType": "application/json",
|
|
408
|
+
"schema": {
|
|
409
|
+
"kind": "object",
|
|
410
|
+
"fields": [
|
|
411
|
+
{ "name": "name", "kind": "single", "type": "string", "required": true, "description": "display name" }
|
|
412
|
+
]
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
"response": {
|
|
417
|
+
"mediaType": "application/json",
|
|
418
|
+
"schema": {
|
|
419
|
+
"kind": "object",
|
|
420
|
+
"fields": [
|
|
421
|
+
{ "name": "id", "kind": "single", "type": "long", "required": true },
|
|
422
|
+
{ "name": "roles", "kind": "array", "items": { "kind": "single", "type": "string" } }
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
**Endpoint order.** `endpoints` is sorted by `folder`, then `name`, `method` and
|
|
432
|
+
`path`; endpoints that belong to no folder come last.
|
|
433
|
+
|
|
434
|
+
**Parameters** are grouped by location under `request.parameters`:
|
|
435
|
+
|
|
436
|
+
| Group | Location | Notes |
|
|
437
|
+
|-------|----------|-------|
|
|
438
|
+
| `path` | path variable | |
|
|
439
|
+
| `query` | query string | |
|
|
440
|
+
| `header` | request header | headers declared outside the parameter list are merged here |
|
|
441
|
+
| `cookie` | cookie | |
|
|
442
|
+
| `form` | form field | `type` is `file` for uploads |
|
|
443
|
+
| `body` | raw body parameter | separate from the `request.body` schema |
|
|
444
|
+
|
|
445
|
+
A group with no parameter is omitted. Order within a group is the order the
|
|
446
|
+
collector reported. Each parameter carries `name`, `type`, `required`, and —
|
|
447
|
+
when the source declares them — `default`, `value`, `description`, `example`
|
|
448
|
+
and `enum`.
|
|
449
|
+
|
|
450
|
+
**Schema** is a tree of nodes, one node per value, shared by request and
|
|
451
|
+
response bodies:
|
|
452
|
+
|
|
453
|
+
| `kind` | Meaning | Keys besides `kind` |
|
|
454
|
+
|--------|---------|---------------------|
|
|
455
|
+
| `single` | primitive | `type`: `string`, `int`, `long`, `float`, `double`, `boolean`, `null` |
|
|
456
|
+
| `ref` | named type left unexpanded | `type`: the type name |
|
|
457
|
+
| `object` | object | `fields`: member nodes |
|
|
458
|
+
| `array` | array | `items`: element node |
|
|
459
|
+
| `map` | map | `key`, `value`: nodes |
|
|
460
|
+
|
|
461
|
+
A member of an object is the same node plus `name`, and the documentation that
|
|
462
|
+
belongs to that member: `required`, `description`, `default`, `demo`, `generic`,
|
|
463
|
+
`options`. Optional keys are omitted when empty, so a field is required only
|
|
464
|
+
when `required` is `true`.
|
|
465
|
+
|
|
466
|
+
Object members are sorted by name. The collected model keeps fields in a map, so
|
|
467
|
+
declaration order is already lost before a formatter runs; sorting is the only
|
|
468
|
+
order that is stable across runs and machines. A type that refers back to itself
|
|
469
|
+
terminates as a `ref` node instead of expanding forever.
|
|
470
|
+
|
|
471
|
+
### YApi
|
|
472
|
+
|
|
473
|
+
`--formatter yapi` saves the endpoints to a [YApi](https://github.com/YMFE/yapi)
|
|
474
|
+
project when it knows the server and the project's token, and prints what it
|
|
475
|
+
created, updated or failed to save:
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
apilot set yapi.server https://yapi.example.com
|
|
479
|
+
apilot set yapi.token <project token>
|
|
480
|
+
apilot export ./backend --formatter yapi
|
|
481
|
+
|
|
482
|
+
# or per run
|
|
483
|
+
apilot export ./backend --formatter yapi --params '{"server":"https://yapi.example.com","token":"<project token>"}'
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
Without a server and a token it prints the interfaces in the JSON that YApi's
|
|
487
|
+
data import accepts.
|
|
488
|
+
|
|
489
|
+
An interface is matched by path and method, so a second export updates the
|
|
490
|
+
first. Interfaces are grouped in categories named after the first line of the
|
|
491
|
+
controller's doc comment, or the controller's name, and created on demand; the
|
|
492
|
+
title is the first line of the endpoint's doc comment and the rest is its
|
|
493
|
+
description. This is how the EasyYapi IntelliJ plugin names them, so exports
|
|
494
|
+
from either tool land in the same place.
|
|
495
|
+
|
|
496
|
+
A project already documented with EasyYapi keeps its rules in
|
|
497
|
+
`.easy.api.config`. The YApi formatter reads that file from the project root
|
|
498
|
+
and from each module directory, and applies the parts that shape a YApi export:
|
|
499
|
+
|
|
500
|
+
| Rule | Effect |
|
|
501
|
+
|------|--------|
|
|
502
|
+
| `json.rule.convert[java.lang.Long]=java.lang.String` | Exports one primitive type as another, e.g. `long` as `string` |
|
|
503
|
+
| `mock.[path\|type]=value` | Mocks every schema node whose JSON path (`data.list[].name`) and JSON type match; `*.` matches any parent, `*` any run of characters, and the first matching rule wins |
|
|
504
|
+
| `properties.additional=<file or URL>` | Includes another rules file at that point |
|
|
505
|
+
| `name=value` and `${name}` | Defines a value and refers to it |
|
|
506
|
+
|
|
507
|
+
Extra rules files can be named with `--params '{"rules":["path/or/url"]}'`.
|
|
508
|
+
Other keys belong to EasyYapi's rule engine and are ignored.
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## IDE integrations
|
|
513
|
+
|
|
514
|
+
- VSCode — via the [APilot VSCode extension](https://marketplace.visualstudio.com/items?itemName=tangcent.apilot) (right-click any folder to export)
|
|
515
|
+
- JetBrains — see [easy-api](https://github.com/tangcent/easy-api) for the IntelliJ plugin
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## Extending APilot
|
|
520
|
+
|
|
521
|
+
APilot has a plugin system. Any binary that speaks the stdin/stdout JSON protocol can be registered as an external collector or formatter — no recompilation needed.
|
|
522
|
+
|
|
523
|
+
```json
|
|
524
|
+
// ~/.config/apilot/plugins.json
|
|
525
|
+
{
|
|
526
|
+
"plugins": [
|
|
527
|
+
{
|
|
528
|
+
"name": "rust",
|
|
529
|
+
"type": "collector",
|
|
530
|
+
"command": "apilot-collector-rust"
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
See [docs/plugin-protocol.md](docs/plugin-protocol.md) for the full protocol spec.
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## Architecture
|
|
541
|
+
|
|
542
|
+
APilot is a multi-module Go monorepo with a clean three-layer design:
|
|
543
|
+
|
|
544
|
+
```
|
|
545
|
+
apilot-cli (bundled binary)
|
|
546
|
+
└── api-master (engine + plugin runtime)
|
|
547
|
+
├── api-collector-{java,go,node,python}
|
|
548
|
+
└── api-formatter-{markdown,curl,json,postman,yapi}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
The `api-collector` and `api-formatter` packages define the stable interfaces. Everything else is an implementation. See [docs/architecture.md](docs/architecture.md) for the full breakdown.
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Contributing
|
|
556
|
+
|
|
557
|
+
PRs and issues are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) to get started.
|
|
558
|
+
|
|
559
|
+
---
|
|
560
|
+
|
|
561
|
+
## License
|
|
562
|
+
|
|
563
|
+
[MIT](LICENSE)
|