mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2025-12-06 00:36:10 +00:00
feat: exclude routes with details.hide: true from OpenAPI/swagger file
This commit is contained in:
@@ -112,6 +112,8 @@ export const swagger = async <Path extends string = '/swagger'>(
|
|||||||
totalRoutes = routes.length
|
totalRoutes = routes.length
|
||||||
|
|
||||||
routes.forEach((route: InternalRoute) => {
|
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
|
if (excludeMethods.includes(route.method)) return
|
||||||
|
|
||||||
registerSchemaPath({
|
registerSchemaPath({
|
||||||
|
|||||||
@@ -200,4 +200,23 @@ describe('Swagger', () => {
|
|||||||
const response = await res.json()
|
const response = await res.json()
|
||||||
expect(response.paths).toContainKey('/id/{id}')
|
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();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user