From 4906dc39241138ee1662b8ac9f5b9bd8135ba804 Mon Sep 17 00:00:00 2001 From: Mikkel ALMONTE--RINGAUD Date: Tue, 13 Jan 2026 10:34:39 +0100 Subject: [PATCH 1/2] feat: add option to hide detail in openapi --- src/index.ts | 34 +++++++++++++++++++++++++++------- src/types.ts | 25 ++++++++++++++++--------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index 113caae..65f3164 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ export async function staticPlugin({ etag: useETag = true, extension = true, indexHTML = true, + hideOpenApiRoute = true, decodeURI, silent }: StaticOptions = {}): Promise { @@ -89,11 +90,16 @@ export async function staticPlugin({ if (isBun && absolutePath.endsWith('.html')) { const htmlBundle = await import(absolutePath) - app.get(pathName, htmlBundle.default) + app.get(pathName, htmlBundle.default, { + detail: { hide: hideOpenApiRoute } + }) if (indexHTML && pathName.endsWith('/index.html')) app.get( pathName.replace('/index.html', ''), - htmlBundle.default + htmlBundle.default, + { + detail: { hide: hideOpenApiRoute } + } ) continue @@ -199,7 +205,10 @@ export async function staticPlugin({ headers: initialHeaders } : undefined - ) + ), + { + detail: { hide: hideOpenApiRoute } + } ) if (indexHTML && pathName.endsWith('/index.html')) @@ -214,7 +223,10 @@ export async function staticPlugin({ headers: initialHeaders } : undefined - ) + ), + { + detail: { hide: hideOpenApiRoute } + } ) } @@ -235,11 +247,16 @@ export async function staticPlugin({ const pathName = normalizePath(path.join(prefix, relativePath)) const htmlBundle = await import(absolutePath) - app.get(pathName, htmlBundle.default) + app.get(pathName, htmlBundle.default, { + detail: { hide: hideOpenApiRoute } + }) if (indexHTML && pathName.endsWith('/index.html')) app.get( pathName.replace('/index.html', ''), - htmlBundle.default + htmlBundle.default, + { + detail: { hide: hideOpenApiRoute } + } ) } } @@ -251,7 +268,7 @@ export async function staticPlugin({ path.join( assets, decodeURI - ? (fastDecodeURI(params['*']) ?? params['*']) + ? fastDecodeURI(params['*']) ?? params['*'] : params['*'] ) ) @@ -328,6 +345,9 @@ export async function staticPlugin({ throw new NotFoundError() } + }, + { + detail: { hide: hideOpenApiRoute } } ) } diff --git a/src/types.ts b/src/types.ts index fa98cef..b598eb3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -106,14 +106,21 @@ export interface StaticOptions { * * @default false */ - decodeURI?: boolean + decodeURI?: boolean - /** - * silent - * - * @default false - * - * If set to true, suppresses all logs and warnings from the static plugin - */ - silent?: boolean + /** + * @default true + * + * Hide routes for OpenAPI and swagger document. + */ + hideOpenApiRoute?: boolean + + /** + * silent + * + * @default false + * + * If set to true, suppresses all logs and warnings from the static plugin + */ + silent?: boolean } From 2bf9b84614b73ede3f4a46e573e8198eb0b666ea Mon Sep 17 00:00:00 2001 From: Mikkel ALMONTE--RINGAUD Date: Tue, 13 Jan 2026 10:39:28 +0100 Subject: [PATCH 2/2] chore: add `hideOpenApiRoute` tests --- test/index.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 6747ff2..3d96773 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -442,4 +442,26 @@ describe('Static Plugin', () => { res = await app.handle(req('/public/html')) expect(res.status).toBe(404) }) + + it('does hide detail for openapi', async () => { + const app = new Elysia().use(staticPlugin()) + await app.modules + + for (const route of app.routes) { + expect(route.hooks.detail.hide).toBeTrue() + } + }) + + it('does not hide detail when hideOpenApiRoute is false', async () => { + const app = new Elysia().use( + staticPlugin({ + hideOpenApiRoute: false + }) + ) + await app.modules + + for (const route of app.routes) { + expect(route.hooks.detail.hide).toBeFalse() + } + }) })