diff --git a/bun.lockb b/bun.lockb index b2fb5df..833d9fe 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/index.ts b/src/index.ts index 2408a58..4b6cff6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -110,8 +110,10 @@ export const swagger = async ( if (routes.length !== totalRoutes) { totalRoutes = routes.length - + routes.forEach((route: InternalRoute) => { + if (route.hooks?.detail?.hide === true) return + // TODO: route.hooks?.detail?.hide !== false add ability to hide: false to prevent excluding if (excludeMethods.includes(route.method)) return registerSchemaPath({ diff --git a/src/utils.ts b/src/utils.ts index 814bf20..cb55b24 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,7 @@ export const registerSchemaPath = ({ models: Record }) => { if (hook) hook = deepClone(hook) - + const contentType = hook?.type ?? [ 'application/json', 'multipart/form-data', diff --git a/test/index.test.ts b/test/index.test.ts index b84c549..7add09b 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -200,4 +200,23 @@ describe('Swagger', () => { const response = await res.json() expect(response.paths).toContainKey('/id/{id}') }) + + it('should hide routes with hide = true from paths', async () => { + const app = new Elysia().use(swagger()) + .get("/public", "omg") + .guard({ + detail: { + hide: true + } + }) + .get("/hidden", "ok") + + await app.modules + + const res = await app.handle(req('/swagger/json')) + expect(res.status).toBe(200) + const response = await res.json() + expect(response.paths['/public']).not.toBeUndefined(); + expect(response.paths['/hidden']).toBeUndefined(); + }) })