Skip to content

Commit 6f2fbd1

Browse files
committed
fix: document path not excluded
1 parent ff6e88e commit 6f2fbd1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const swagger =
146146
...documentation.info
147147
}
148148
},
149-
paths: {...filterPaths(schema, {
149+
paths: {...filterPaths(schema, relativePath, {
150150
excludeStaticFile,
151151
exclude: Array.isArray(exclude) ? exclude : [exclude]
152152
}),

src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
import path from 'path'
34
import type { HTTPMethod, LocalHook } from 'elysia'
45

56
import { Kind, type TSchema } from '@sinclair/typebox'
@@ -282,6 +283,7 @@ export const registerSchemaPath = ({
282283

283284
export const filterPaths = (
284285
paths: Record<string, any>,
286+
docsPath: string,
285287
{
286288
excludeStaticFile = true,
287289
exclude = []
@@ -292,14 +294,19 @@ export const filterPaths = (
292294
) => {
293295
const newPaths: Record<string, any> = {}
294296

297+
// exclude docs path and OpenAPI json path
298+
const excludePaths = [`/${docsPath}`, `/${docsPath}/json`].map((p) =>
299+
path.normalize(p)
300+
)
301+
295302
for (const [key, value] of Object.entries(paths))
296303
if (
297304
!exclude.some((x) => {
298305
if (typeof x === 'string') return key === x
299306

300307
return x.test(key)
301308
}) &&
302-
!key.includes('/swagger') &&
309+
!excludePaths.includes(key) &&
303310
!key.includes('*') &&
304311
(excludeStaticFile ? !key.includes('.') : true)
305312
) {

0 commit comments

Comments
 (0)