Skip to content

Conversation

marcalexiei
Copy link

@marcalexiei marcalexiei commented Oct 8, 2025

Summary by CodeRabbit

  • New Features

    • Added support for regex-based path exclusions in OpenAPI generation alongside exact string matches, so you can flexibly control which routes appear in the generated spec.
  • Tests

    • Added tests to confirm excluded paths—both regex patterns and exact strings—are omitted from the produced OpenAPI output, ensuring only intended routes are included.

Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

Replaces exact-match exclusion for OpenAPI route filtering with a matcher that treats string entries as exact matches and non-string entries as regular expressions; routes are skipped when any matcher matches. Adds a test verifying mixed regex and string exclusions.

Changes

Cohort / File(s) Summary
OpenAPI path exclusion logic
src/openapi.ts
Replaces a direct equality check with a some-based matcher: if an exclude.paths entry is a string it must equal the route path; otherwise it is treated as a RegExp and .test(path) is used. Matching routes are skipped from the generated spec.
Tests for exclude.paths behavior
test/index.test.ts
Adds a test that configures exclude.paths with /^\/v1/ and "/v2", registers routes /, /v1, /v1/foo, /v2, and asserts the generated OpenAPI includes only /.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as Elysia App
  participant OA as OpenAPI Plugin
  participant Ex as exclude.paths
  participant Gen as OpenAPI Generator

  App->>OA: initialize plugin with options
  OA->>Gen: request spec generation
  loop for each route
    Gen->>Ex: evaluate matchers (some over entries)
    alt matcher is string and equals path OR matcher is RegExp and test(path) true
      Gen-->>Gen: skip route (excluded)
      Note right of Gen #ffe599: Excluded by string or RegExp
    else
      Gen-->>Gen: include route in spec
      Note right of Gen #d9ead3: Included in output
    end
  end
  Gen-->>App: return OpenAPI JSON
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, sniff the streams,
Regex trails and stringly dreams.
"/v1" hides beneath my paw,
"/v2" retreats—I check the law.
Only "/" hops into the beams. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title precisely states the primary fix for RegExp support in exclude.paths, aligning with the changes that update the path exclusion logic to handle regex entries.
Linked Issues Check ✅ Passed The updated exclusion logic now treats RegExp entries by testing them against each route and existing tests confirm that both the regex /^\\/v1/ and the string /v2 correctly omit the matching paths from the OpenAPI output, satisfying the requirements of issue #275.
Out of Scope Changes Check ✅ Passed The only modifications are to the exclusion logic and the corresponding test case for exclude.paths, with no unrelated files or features altered, so there are no out-of-scope changes in this PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41602e1 and 4544611.

📒 Files selected for processing (2)
  • src/openapi.ts (1 hunks)
  • test/index.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/openapi.ts
  • test/index.test.ts

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/openapi.ts (1)

317-322: Prefer .test() for RegExp matching.

The logic correctly enables regex-based path exclusion, but .exec() returns an array or null, relying on truthiness. Use .test() for clarity, as it directly returns a boolean.

Apply this diff:

 excludePaths.some(match => {
 	if (typeof match === 'string') {
 		return match === route.path
 	}
-	return match.exec(route.path);
+	return match.test(route.path);
 })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 070919e and 8f5e4b8.

📒 Files selected for processing (2)
  • src/openapi.ts (1 hunks)
  • test/index.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/index.test.ts (1)
src/index.ts (1)
  • openapi (40-181)

@marcalexiei marcalexiei force-pushed the fix/exclude-paths-regexp branch 2 times, most recently from 2e297d8 to 41602e1 Compare October 8, 2025 13:19
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/index.test.ts (1)

289-289: Consider removing the trailing semicolon for consistency.

The trailing semicolon on line 289 is slightly inconsistent with the predominant style in the file, where most method chains end without semicolons. While this is a minor stylistic issue, removing it would improve consistency.

Apply this diff if you prefer consistency:

-		.get("/v2", () => "v2");
+		.get("/v2", () => "v2")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5e4b8 and 41602e1.

📒 Files selected for processing (2)
  • src/openapi.ts (1 hunks)
  • test/index.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openapi.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/index.test.ts (1)
src/index.ts (1)
  • openapi (40-181)
🔇 Additional comments (1)
test/index.test.ts (1)

276-297: LGTM! Test correctly validates regex and string exclusion.

The test properly verifies that:

  • Regex patterns (e.g., /^\/v1/) exclude matching routes like "/v1" and "/v1/foo"
  • Exact string matches (e.g., "/v2") exclude only that specific path
  • Non-excluded routes (e.g., "/") remain in the generated OpenAPI spec

The previous issues flagged in earlier reviews (.only() modifier and .listen(3000) call) have been correctly addressed.

@marcalexiei marcalexiei force-pushed the fix/exclude-paths-regexp branch from 41602e1 to 4544611 Compare October 8, 2025 13:26
@marcalexiei
Copy link
Author

@coderabbitai review

Copy link

coderabbitai bot commented Oct 8, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

bug: exclude.paths is not working when using RegExp
1 participant