Skip to content

feat: support RegExp patterns in exclude.paths#326

Open
yanncabral wants to merge 2 commits into
elysiajs:mainfrom
yanncabral:fix/openapi-exclude
Open

feat: support RegExp patterns in exclude.paths#326
yanncabral wants to merge 2 commits into
elysiajs:mainfrom
yanncabral:fix/openapi-exclude

Conversation

@yanncabral

Copy link
Copy Markdown

🚀 Summary

This PR introduces support for Regular Expressions in the exclude.paths configuration. Previously, the plugin only supported exact string matches, making it difficult to exclude large sets of routes or dynamic path segments.

🛠️ The Problem

When managing large APIs, users often need to exclude entire modules, versions, or internal tools (e.g., all /v1 or /internal routes) from the OpenAPI documentation.
Using the current implementation:

  • Users had to list every single path manually as a string.
  • There was no support for wildcards or pattern-based filtering.
  • Managing long lists of excluded paths was error-prone and tedious.

✨ The Solution

I have updated the toOpenAPISchema logic to handle both strings and RegExp objects within the exclude.paths array.

  1. Pattern Extraction: The plugin now filters the exclusion list to pre-compute all provided RegExp instances.
  2. Type Safety: Implemented a TypeScript type predicate (path is RegExp) to ensure explicit narrowing and type safety when testing patterns.
  3. Dynamic Testing: During schema generation, each route is checked against these patterns using .test(route.path).
  4. Compatibility: This change is fully backward compatible with the existing string-based exclusion logic.

📝 Technical Changes

  • src/openapi.ts:
    • Added ignorePatterns with explicit RegExp[] typing.
    • Used a type predicate for the .filter() call to correctly narrow types.
    • Integrated pattern.test(route.path) logic inside the route mapping loop.

📖 Example Usage

Now you can easily exclude all routes starting with a specific prefix:

app.use(
  openapi({
    exclude: {
      paths: [
        /^\/v1/,         // Excludes all routes starting with /v1
        /^\/admin/,      // Excludes all admin routes
        '/health-check'  // Still supports exact strings
      ]
    }
  })
)

@coderabbitai

coderabbitai Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@yanncabral has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant