Commit fc007cd
authored
cli: OpenAPI-driven subcommand fallback behind VERCEL_AUTO_API (#15989)
## Summary
Adds OpenAPI-driven subcommand resolution behind the `VERCEL_AUTO_API=1`
environment variable. When enabled:
- **Top-level tag resolution** — unrecognized CLI tokens are matched
against OpenAPI tags from `openapi.vercel.sh`, enabling `vercel <tag>
<operationId>` (e.g. `vercel user getAuthUser`, `vercel teams list`).
- **Per-command fallthrough** — commands like `vercel projects` fall
through to OpenAPI tag/operation matching when a token doesn't match a
native subcommand (e.g. `vercel projects getProject`).
- **`x-vercel-cli` metadata** — operations opt in via
`x-vercel-cli.supportedSubcommands: true` in the OpenAPI spec. Aliases
(`x-vercel-cli.aliases`), positional arguments (`x-vercel-cli.kind:
'argument'`), and response formatting (`x-vercel-cli.displayColumns`)
are all driven by the spec.
- **Formatted output** — when `displayColumns` is present in the
response schema, results render as a card (single object) or table
(array) instead of raw JSON.
- The `vercel api` subcommand itself is unchanged — it continues to
handle direct endpoint paths and interactive mode only.
### New files
- `commands/api/display-columns.ts` — card/table renderers driven by
`displayColumns` dot-notation paths
- `commands/api/operation-request-builder.ts` — builds API requests from
OpenAPI operation specs with interactive prompting
- `util/openapi/matches-cli-api-tag.ts` — checks if a string matches an
OpenAPI tag
- `util/openapi/resolve-by-tag-operation.ts` — resolves tag +
operationId to an endpoint
- `util/openapi/resolve-subcommand-with-openapi.ts` — merges native
subcommands with OpenAPI fallback
- `util/openapi/try-openapi-fallback.ts` — reusable fallback entry point
used by top-level and per-command routing
## Test plan
- [x] Unit tests for `matches-cli-api-tag`, `resolve-by-tag-operation`,
`resolve-subcommand-with-openapi`, `operation-request-builder`
- [x] Unit tests for `client._fetch` teamId preservation
- [ ] Manual: `VERCEL_AUTO_API=1 vercel user getAuthUser` renders card
with displayColumns
- [ ] Manual: `VERCEL_AUTO_API=1 vercel teams list` renders table
- [ ] Manual: `VERCEL_AUTO_API=1 vercel teams get <teamId>` renders card
- [ ] Manual: `vercel user getAuthUser` (without env var) falls through
to normal behavior
- [ ] Manual: `vercel projects list` still works as native subcommand1 parent 7a5b910 commit fc007cd
26 files changed
Lines changed: 163337 additions & 68 deletions
File tree
- .changeset
- packages/cli
- src
- commands
- api
- project
- teams
- util
- openapi
- telemetry/commands/api
- test
- fixtures/unit
- unit
- commands/api
- util
- openapi
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 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 | + | |
0 commit comments