Skip to content

feat: add hideOpenApiRoute option to hide detail in openapi generation#59

Open
Vexcited wants to merge 2 commits intoelysiajs:mainfrom
Vexcited:main
Open

feat: add hideOpenApiRoute option to hide detail in openapi generation#59
Vexcited wants to merge 2 commits intoelysiajs:mainfrom
Vexcited:main

Conversation

@Vexcited
Copy link

@Vexcited Vexcited commented Jan 13, 2026

I use Elysia as a full stack framework that uses elysia-static to deploy my built Vite app.
Unfortunately, this plugin does not hide by default the routes so in my generated OpenAPI, I can see the static routes too!

Example on a demo application with my prefix set to /.

image

GET /* and that empty GET one should NOT be displayed.

To resolve this issue, I propose an option to hide details for OpenAPI (detail: { hide: true }) by adding the hideOpenApiRoute property (true by default) to the configuration of the plugin.

If I apply this PR to the previous demo application, I now get the following, which is way clearer.

image

Summary by CodeRabbit

  • New Features

    • Added hideOpenApiRoute configuration option to the Static Plugin (enabled by default) that controls OpenAPI and Swagger route visibility.
  • Tests

    • Added test coverage verifying route hiding behavior with the new option enabled and disabled.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Walkthrough

The PR introduces a new hideOpenApiRoute option (default true) to the staticPlugin that allows controlling whether static routes appear in OpenAPI documentation. This option is propagated as metadata to all registered routes via a detail: { hide: hideOpenApiRoute } object.

Changes

Cohort / File(s) Summary
Type Definitions
src/types.ts
Added hideOpenApiRoute?: boolean property to StaticOptions<Prefix> interface to support the new configuration option.
Core Implementation
src/index.ts
Extracted hideOpenApiRoute from plugin options (defaulting to true) and attached detail: { hide: hideOpenApiRoute } metadata to all static file routes, HTML bundle routes, and error handling routes via app.get() and app.onError() calls.
Test Coverage
test/index.test.ts
Added two new test cases verifying that route metadata is correctly set: one confirming routes are hidden by default, and another confirming the behavior when hideOpenApiRoute: false.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A flag to hide the paths unseen,
Routes tucked behind OpenAPI's screen,
Default true, but turneth when you please,
Static assets dance with metadata ease!
Hopping through the documentation breeze ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature being added: a new hideOpenApiRoute option to hide route details in OpenAPI generation, which aligns with the changeset modifications to src/index.ts, src/types.ts, and test/index.test.ts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d12f68 and 2bf9b84.

📒 Files selected for processing (3)
  • src/index.ts
  • src/types.ts
  • test/index.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/index.test.ts (1)
src/index.ts (1)
  • staticPlugin (21-356)
🔇 Additional comments (9)
src/index.ts (5)

33-33: LGTM - Good default choice.

Defaulting hideOpenApiRoute to true is sensible for static file routes since they typically shouldn't appear in API documentation.


93-103: LGTM - Consistent application of detail.hide to HTML bundle routes.

Both the primary HTML route and the index.html alias route correctly receive the hideOpenApiRoute configuration.


197-230: LGTM - detail.hide properly applied to static file routes.

The option is correctly propagated to both ETag-enabled and ETag-disabled static file routes, including the index.html path variants.


250-260: LGTM - HTML routes in dynamic mode correctly configured.

Both the main HTML path and the index.html shortcut path receive the hideOpenApiRoute setting.


348-352: LGTM - Wildcard route handler includes detail.hide.

The catch-all route for dynamic file serving correctly applies the hideOpenApiRoute option.

src/types.ts (2)

111-116: LGTM - Well-documented option.

The JSDoc clearly explains the purpose and default value of hideOpenApiRoute.


118-125: Verify if silent option documentation is intentionally part of this PR.

The silent option documentation appears to be added in this PR. If this was previously undocumented, it's a good addition. Otherwise, confirm this change is intentional.

test/index.test.ts (2)

455-466: LGTM - Good test for explicit false case.

Testing with hideOpenApiRoute: false properly verifies the opt-out behavior.


446-453: The test is correct and does not require defensive access.

All routes created by staticPlugin explicitly set the detail: { hide: hideOpenApiRoute } option (lines 94, 101, 210, 228, 251, 258, and 350 in src/index.ts), which guarantees that route.hooks.detail will be defined for every route in the app. Since the test only uses staticPlugin() with no additional routes, all routes in app.routes will have hooks.detail present, making the direct access safe and the test valid as-is.

Likely an incorrect or invalid review 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