feat: root-config filtering of channels/operations (AsyncAPI) and paths (OpenAPI)#431
Open
jonaslagoni wants to merge 16 commits into
Open
feat: root-config filtering of channels/operations (AsyncAPI) and paths (OpenAPI)#431jonaslagoni wants to merge 16 commits into
jonaslagoni wants to merge 16 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AsyncAPI (asyncapi-regular) and OpenAPI (new openapi-filter.json) filter configs plus filter.spec.ts asserting kept surfaces exist and dropped surfaces + orphaned models are absent. Specs currently RED against the unfiltered generation, as intended. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…D GREEN) filterAsyncapiJson does model-read keep-set computation, version-aware JSON surgery (v2 publish/subscribe, v3 dual-map + components mirrors), and orphan schema pruning. Wired into Node file/in-memory and browser loaders with early-return on inactive filter. Loader signatures moved to object params; all call sites updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… RED) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…aders (TDD GREEN) filterOpenapiDocument does path/method deletion (explicit HTTP-method whitelist, derived operationId matching) and reachability-based orphan pruning of components.schemas/definitions via x-modelgen-inferred-name. Wired into Node file/in-memory + browser OpenAPI loaders. Added normalizeFilter so partial filters (root Zod defaults not re-materialized by realizeConfiguration) don't crash. Loader signatures moved to object params; all call sites updated. Runtime filter.spec now GREEN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…all flows Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated all runtime configs cleanly (incl. the two filter configs) and committed the filtered payload output. filter.spec.ts passes: kept surfaces generated, dropped surfaces + orphaned models absent. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rated docs markdown-toc appends a trailing newline on each run and oclif readme embeds the local platform/node version; neither is a real change. Restored README.md, contributing.md, migrations/v0.md, usage.md to base so the PR carries only the intended filter docs + regenerated schemas. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
De-duplicated the recursive reachability collector shared by the AsyncAPI and OpenAPI orphan-pruning helpers into a single collectExtensionValues primitive in src/codegen/filter.ts, keyed on the extension name each parser uses. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ALagoni97
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in, default-off root-config
filteroption that restricts code generation to a subset of an input document — specific AsyncAPI channels/operations or OpenAPI paths/operations — instead of everything. Filtering happens once, while the document is loaded, so every downstream generator (payloads, parameters, headers, types, channels, client, protocols) sees the already-subsetted document with no per-generator changes.Component schemas (and, for AsyncAPI, messages) left orphaned by the filtering are pruned automatically. JSON Schema input has no
filter(no channels/paths to filter).Why
Users frequently want to generate code for only part of a large specification — a single API surface, one channel family, or excluding internal endpoints — without hand-editing the source document. The existing per-generator
includeChannels/includeHeadersflags are on/off toggles, not per-item selectors. A single root-level filter, applied at load time, covers every generator and every protocol uniformly.Changes
Config surface
zodInputFilter(include/excludeglob string arrays, both defaulted) attached to the AsyncAPI and OpenAPI config branches only (src/codegen/types.ts).minimatch@^9.0.5added as a direct dependency (already hoisted transitively, browser-safe).schemas/*.jsonfrom the Zod source.Matching primitive (
src/codegen/filter.ts)matchesFilter({candidates, include, exclude})— minimatch globs; emptyinclude= match-all,excludeapplied afterinclude, multi-candidate OR-match.normalizeFilter/isFilterActivehelpers and a shared recursivecollectExtensionValuesreachability walker.AsyncAPI filter (
src/codegen/inputs/asyncapi/filter.ts)publish/subscribenesting; v3 top-leveloperations+ dropping the redundantcomponents.channels/operations/messagesmirrors to avoid re-parse double-counting), prunes orphanedcomponents.schemas, and re-parses with the loader's own parser instance. Works for v2 and v3.OpenAPI filter (
src/codegen/inputs/openapi/filter.ts)parameters/summarypreserved), derived-operationIdmatching, and reachability-based orphan pruning ofcomponents.schemas(3.x) /definitions(2.0) viax-modelgen-inferred-name.Loader wiring
realizeGeneratorContext), Node in-memory (realizeInMemoryGeneratorContext), and browser (src/browser/generate.ts/src/browser/parser.ts). Loader signatures moved to object parameters; all call sites (incl. tests) updated. Loaders early-return the unfiltered document when the filter is inactive.Example + docs
examples/openapi-filtering/(runnable, with README and committed output).docs/configurations.mdfilter section +docs/inputs/asyncapi.md/openapi.mdnotes.Testing
npm test): 36 new tests — glob semantics (test/codegen/filter.test.ts), AsyncAPI v2+v3 retention/dual-map/orphan pruning (test/codegen/inputs/asyncapi/filter.test.ts), OpenAPI v2+v3 path/method/derived-id/orphan pruning (test/codegen/inputs/openapi/filter.test.ts), and config parsing/defaults/branch-presence (test/codegen/configurations.spec.ts).test/runtime/typescript/test/filter.spec.ts): asserts kept surfaces are generated + behave, dropped surfaces are absent, and orphaned models are pruned, over real filtered generation.Verification run on this branch:
npm run buildnpm run lint(eslint max-warnings 0 + typecheck:test)npm test— 56 suites, 717 passed / 1 skipped, 78 snapshotsfilter.spec.ts(8 passed; payloads preset, no brokers required)Notes
filter(every existing config) the loaders early-return before any filtering and output is unchanged — confirmed by the unchanged snapshots. Not a major version bump.src/drift (out of scope): regenerating the runtime project surfaced three pre-existinghttp_client.tsfiles that were stale relative to the mergedHttpErrorfeature (feat: typed HttpError + input-driven error handling #429). They are unrelated to filtering and were intentionally left out of this PR — they should be regenerated + committed separately.prepare:prwas validated via its constituent steps (build → generate:assets → lint:fix → test:update → runtime generate); thenpm cistep is skipped per the known runtime lockfile-drift caveat.--filterflag, no regex/tag/predicate filters, no--dry-runreport of what was filtered.