Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export function toOpenAPISchema(
continue

const hooks: InputSchema & {
detail: Partial<OpenAPIV3.OperationObject>
detail?: Partial<OpenAPIV3.OperationObject>
} = route.hooks ?? {}

if (references?.length)
Expand Down Expand Up @@ -380,7 +380,7 @@ export function toOpenAPISchema(

if (
excludeTags &&
hooks.detail.tags?.some((tag) => excludeTags?.includes(tag))
hooks.detail?.tags?.some((tag) => excludeTags?.includes(tag))
)
continue

Expand Down
34 changes: 34 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,38 @@ describe('Swagger', () => {
const response = await res.json()
expect(Object.keys(response.paths['/all'])).toBeArrayOfSize(8)
})

// https://github.com/elysiajs/elysia-openapi/issues/273
it('should exclude routes with specified tags', async () => {
const app = new Elysia()
.use(
openapi({
exclude: {
tags: ['internal']
}
})
)
.get('/', () => 'index')
.get('/healthz', () => ({ status: 'ok' }), {
detail: {
tags: ['internal']
}
})

await app.modules

const res = await app.handle(req('/openapi/json'))
expect(res.status).toBe(200)
const response = await res.json()

// Check that only root path is included
expect(Object.keys(response.paths)).toEqual(['/'])

// Verify /healthz is excluded
expect(response.paths['/healthz']).toBeUndefined()

// Verify root path is included and has GET method
expect(response.paths['/']).toBeDefined()
expect(response.paths['/'].get).toBeDefined()
})
})