Repository navigation
Commit 64c5668
feat(connector-openapi): normalize-openapi --trim writes only the operations --include-pattern matches (#28331)
Fixes #28309
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:离线脚本 `normalize-openapi` 新增 `--trim` 开关,配合 `--include-pattern`
只写出被匹配的操作;两处文档同步。
- 为什么改:大型厂商文档(Stripe 612 个操作、63 MB)原样打包不现实;Stripe 连接器应用要求打包文件就是脚本输出并记录其
sha256。
- 风险与回滚:只改仓库脚本(不随 npm 发布)与文档;不加 `--trim` 时输出逐字节不变;回滚即 revert 本 PR。
-
先看:`packages/connectors/connector-openapi/scripts/normalize-openapi.mts`
的 `trimPaths` 与第 4 步前的裁剪调用;其测试文件的 `--trim`
一节;`content/docs/automation/connectors.mdx` 新段落。
- 两分钟验证:`pnpm --filter @objectstack/connector-openapi exec vitest run
scripts/normalize-openapi.test.ts`,预期 20 个测试全部通过。
- 需要你做的:无,席位落地。
## What changes
- `scripts/normalize-openapi.mts` gains `--trim` (option `trim` on
`normalizeOpenApi`). With it, every path operation no
`--include-pattern` matches, every path item left with no operation, and
`webhooks` are dropped **before** dereferencing, so only the kept
operations are walked and nothing reachable only from a dropped
operation reaches the output. A `$ref` path item is resolved (not
walked) before its operations are selected. The `include` list is
computed exactly as before (same patterns, same imported
`operationActionKey`), and the printed `sha256` is still the hash of the
bytes written, which are now the trimmed bytes. The summary gains
`trimmedFrom` (operations in the source) when trimming. `--trim` with no
`--include-pattern` is refused (exit 1); a pattern matching nothing is
refused as before.
- `securitySchemes` stay, as in the untrimmed path (they are referenced
by name, never by `$ref`, and the provider does not read them); every
other component was already dropped after inlining, and under `--trim`
it is never reached from a dropped operation.
- Docs: `content/docs/automation/connectors.mdx` (the script's
paragraph: the example command now carries `--trim`, and a new paragraph
says what trimming writes and when to leave it off);
`content/docs/deployment/marketplace-handbook.mdx`, the one
README-section sentence that still described the normalizer as
forthcoming now says how a declarative OpenAPI app produces its packaged
document and which sha256 to record.
- The runtime (`src/**`) does not change; the script stays a repository
script (not in `files[]`, no `bin`), so this carries `skip-changeset`.
### Why a separate `--trim` flag, not trimming whenever
`--include-pattern` is given
- An implied trim changes what the one documented command writes (its
bytes and its hash) with no change to the command line. With a flag,
every existing invocation writes exactly what it wrote before: the
untrimmed Stripe run below reproduces the #28276 reading byte for byte.
- The two outputs serve two different authors. Untrimmed plus `include`
lets an app widen `include` later by editing config alone; trimmed means
widening requires re-running the script. Which one an app wants is the
author's call, and the command line that produced the packaged bytes
should say which one it was.
- Today's callers: the only documented call is the example in
`connectors.mdx` (the shelf pipeline is not built yet), so the flag
costs nobody a migration; the example now uses `--trim`, which is what
recipe 1 teaches (trim to the operations the app calls).
## Tests
`scripts/normalize-openapi.test.ts`, on the existing fixtures, a new
`--trim` block and one new CLI case:
- the trimmed output holds exactly the matched operations
(`GetCustomers`, `GetCustomersCustomer`, `get_v1_balance`), drops the
unmatched POST from a path item whose GET is kept, has the same
`include` list as the untrimmed run, loads through
`createOpenApiProviderFactory` with exactly those actions and no `$ref`
in the document or the materialized def;
- trimming to `balance` alone drops the customer path items and leaves
no text reachable only from them (`A customer.`, `Error response.`, the
shared `limit` parameter, `subscription`), with zero cuts counted (only
the kept operation was walked);
- a Swagger 2.0 document is trimmed after conversion, keyed by
`operationId`;
- a `$ref` path item is resolved before selection (its sibling `summary`
kept) and `webhooks` are dropped;
- refusals: `--trim` with no pattern; a pattern matching nothing;
- control: without `--trim` the whole document is written, as before;
- CLI: with `--trim`, `bytes` and `sha256` equal the written file's
length and `sha256` of its bytes, `operations` is 2 and `trimmedFrom` is
4; `--trim` alone exits 1 and writes nothing.
<details><summary>Package test and typecheck (head 08bf282)</summary>
```text
pnpm --filter @objectstack/connector-openapi test && pnpm --filter @objectstack/connector-openapi typecheck
Test Files 6 passed (6)
Tests 82 passed (82)
check:test-typecheck: OK — @objectstack/connector-openapi's test layer compiles under packages/connectors/connector-openapi/tsconfig.test.json
os-verify-lock: VERDICT command-exit 0
scripts/normalize-openapi.test.ts alone: Tests 20 passed (20) (13 before this PR, 7 new)
```
</details>
<details><summary>Ablation (one-off, committed fix first,
restored)</summary>
`node scripts/ablation-replace.mjs` on `normalize-openapi.mts`, anchor
`if (matches(patterns, { key: operationActionKey(...` (hits 1 to 0, blob
a2190cd to 70610c5bb588) replaced by a condition that keeps every
operation. The test file then reads `Tests 5 failed | 15 passed (20)`:
the four trim selection cases and the CLI `--trim` case went red; the
refusal and control cases stayed green, as expected. Restored: blob
equals HEAD (a2190cd) and `git diff HEAD` is empty. No build or
`dist/` leg: the test imports the script from source.
</details>
## Acceptance notes
Measured once against the real Stripe document, `stripe/openapi`
`openapi/spec3.json` at `51610f5f` (MIT; 8,317,513 bytes, sha256
`7cff4cc46d0654101a36a3302f7544640f5f73e4f3cad6f264f0e23c19fa1776`),
with the pattern
`^(GetCustomers|PostCustomers|GetCustomersCustomer|GetCharges|PostPaymentIntents|GetPaymentIntentsIntent)$`
at the default `--max-depth 2`:
| run | bytes | operations | sha256 |
|:---|---:|---:|:---|
| without `--trim` (control) | 63,317,655 | 612 |
`0ea3c37a0854ad2646a156404b1ef86cca57403855e3803cd4630601eb6fc7b2` |
| with `--trim` | 1,934,435 | 6 (`trimmedFrom` 612) |
`08d6e40bccec707a0bfc355b1cbf936df29018c22e7be658d616683e501b13d4` |
- The control equals the #28276 dev's reading byte for byte (same size,
same hash), so the untrimmed path is unchanged on the real document.
- `sha256sum` of the trimmed file equals the printed hash; `refsLeft` 0;
cuts recursive 38, max-depth 1064, extension 240; the two runs print the
same `include` list.
- The trimmed file loads through `createOpenApiProviderFactory` with
exactly the six actions and zero `$ref` keys in the text and in the
materialized def.
- The trimmed size is about 1.9 MB, not the about 1.1 MB the card
quoted: the #28276 dev's six operations are not named on that card, so
this is a different six (two of them creates carrying request bodies).
The number is a reading of this pattern, not a target.
## Verification
<details><summary>Derived gates (dispatch-gates --commands --repo
objectstack-ai/objectstack, head 08bf282)</summary>
78 commands derived from the 4 changed paths; each run with its exit
code captured before any pipe. `--ran` reconciliation: 78 derived, 78
run, 0 NOT-MEASURED (a derived zero). On the first run (head e6e7833)
`check:skill-examples` and `check:dual-build-cjs-loads` answered exit 3
PREREQUISITE NOT MET (unbuilt sibling packages); after building the
`@objectstack/client-react` closure both measured exit 0. Re-run in full
on the final head 08bf282 (after merging origin/main): all 78 exit 0.
</details>
Not run locally, by rule: `test:repo`, `pnpm lint` and the other
repo-wide scans (CI).
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcVBKAFk1ntXSjvPt7U)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3fd8033 commit 64c5668
4 files changed
Lines changed: 283 additions & 29 deletions
File tree
- content/docs
- automation
- deployment
- packages/connectors/connector-openapi/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
190 | 201 | | |
191 | 202 | | |
192 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
31 | 47 | | |
32 | 48 | | |
33 | 49 | | |
| |||
89 | 105 | | |
90 | 106 | | |
91 | 107 | | |
| 108 | + | |
| 109 | + | |
92 | 110 | | |
93 | 111 | | |
94 | 112 | | |
| |||
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
116 | | - | |
| 134 | + | |
117 | 135 | | |
| 136 | + | |
| 137 | + | |
118 | 138 | | |
119 | 139 | | |
120 | 140 | | |
| |||
145 | 165 | | |
146 | 166 | | |
147 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
148 | 174 | | |
149 | 175 | | |
150 | 176 | | |
| |||
212 | 238 | | |
213 | 239 | | |
214 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
215 | 250 | | |
216 | 251 | | |
217 | 252 | | |
| |||
230 | 265 | | |
231 | 266 | | |
232 | 267 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
254 | 271 | | |
255 | 272 | | |
256 | 273 | | |
| |||
263 | 280 | | |
264 | 281 | | |
265 | 282 | | |
| 283 | + | |
266 | 284 | | |
267 | 285 | | |
268 | 286 | | |
269 | 287 | | |
270 | 288 | | |
271 | 289 | | |
272 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
273 | 357 | | |
274 | 358 | | |
275 | 359 | | |
| |||
391 | 475 | | |
392 | 476 | | |
393 | 477 | | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
394 | 499 | | |
395 | 500 | | |
396 | 501 | | |
| |||
537 | 642 | | |
538 | 643 | | |
539 | 644 | | |
540 | | - | |
| 645 | + | |
541 | 646 | | |
542 | 647 | | |
543 | 648 | | |
| |||
547 | 652 | | |
548 | 653 | | |
549 | 654 | | |
| 655 | + | |
550 | 656 | | |
551 | 657 | | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
552 | 662 | | |
553 | 663 | | |
554 | 664 | | |
| |||
573 | 683 | | |
574 | 684 | | |
575 | 685 | | |
| 686 | + | |
576 | 687 | | |
577 | 688 | | |
578 | 689 | | |
| |||
590 | 701 | | |
591 | 702 | | |
592 | 703 | | |
| 704 | + | |
593 | 705 | | |
594 | 706 | | |
595 | 707 | | |
| |||
0 commit comments