From 45446117250d4f605e52196ddcd0ff9c43702795 Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti Date: Wed, 8 Oct 2025 15:05:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20`exclude.paths`=20is=20no?= =?UTF-8?q?t=20working=20when=20using=20RegExp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/openapi.ts | 7 ++++++- test/index.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/openapi.ts b/src/openapi.ts index d99e9c7..43c4990 100644 --- a/src/openapi.ts +++ b/src/openapi.ts @@ -314,7 +314,12 @@ export function toOpenAPISchema( if ( (excludeStaticFile && route.path.includes('.')) || - excludePaths.includes(route.path) || + excludePaths.some(match => { + if (typeof match === 'string') { + return match === route.path + } + return match.exec(route.path); + }) || excludeMethods.includes(method) ) continue diff --git a/test/index.test.ts b/test/index.test.ts index 9c61e47..54fc790 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -272,4 +272,27 @@ describe('Swagger', () => { const response = await res.json() expect(Object.keys(response.paths['/all'])).toBeArrayOfSize(8) }) + + // https://github.com/elysiajs/elysia-openapi/issues/275 + it('should exclude entry points excluded by `exclude.path` option', async () => { + const app = new Elysia() + .use( + openapi({ + exclude: { + paths: [/^\/v1/, "/v2"], + }, + }) + ) + .get("/", () => "index") + .get("/v1", () => "v1") + .get("/v1/foo", () => "v1") + .get("/v2", () => "v2") + + await app.modules + + const res = await app.handle(req('/openapi/json')) + expect(res.status).toBe(200) + const response = await res.json() + expect(Object.keys(response.paths)).toStrictEqual(["/"]) + }) })