feat(openapi-typescript): new feature to generate a subset of the api definition by filtering paths#2836
Open
tqml wants to merge 4 commits into
Open
feat(openapi-typescript): new feature to generate a subset of the api definition by filtering paths#2836tqml wants to merge 4 commits into
tqml wants to merge 4 commits into
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
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.
Add
pathsFilteroption to generate a subset of API pathsMotivation
Generated TypeScript clients for large APIs (e.g. GitHub, Stripe) can be extremely large — tens of thousands of lines — even when a project only consumes a handful of endpoints. There was no way to scope the output to a relevant subset without manually editing the schema file.
Note: the code was written and reviewed by AI, but also again reviewed and tested by me.
What this PR does
Adds a new
pathsFilteroption toOpenAPITSOptions:(pathname, method)combination and returnstrueto include it orfalseto exclude it$reftargets no longer reachable from the included paths are removed transitively, so unused models don't appear in the outputmethodis always lowercase;pathnameis passed as-is (OpenAPI paths are case-sensitive and are not normalized)$ref(e.g."/users": { $ref: "..." }) are always included regardless of the filter, since individual methods cannot be inspected without resolving the reference. This is documented in the JSDoc.PathsFilterFntype is exported from the package for consumers who want to explicitly type a standalone filter functionFiles changed
src/lib/filter.tsapplyPathsFilterimplementation with transitive ref tree-shakingsrc/index.tsvalidateAndBundle, before AST transformation; exportPathsFilterFnsrc/types.tspathsFiltertoOpenAPITSOptionswith full JSDoctest/lib/filter.test.tsexamples/github-api-pulls-only.tsscripts/generate-github-pulls-only.tsscripts/update-examples.tsAI disclosure
This feature was implemented, tested, and reviewed with the assistance of Claude (Sonnet 4.6) in May 2026 using the following prompt:
A subsequent code review session identified and addressed the following:
$refpath items bypass the filter (known limitation)methodis always lowercase and pathnames are not normalizedPathsFilterFnfrom the public API