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
7 changes: 6 additions & 1 deletion src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(["/"])
})
})