diff --git a/src/index.ts b/src/index.ts index a247e45..ea13308 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,7 @@ export const swagger = ...documentation.info } }, - paths: {...filterPaths(schema, { + paths: {...filterPaths(schema, relativePath, { excludeStaticFile, exclude: Array.isArray(exclude) ? exclude : [exclude] }), diff --git a/src/utils.ts b/src/utils.ts index bd2ed5a..19c94b6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable @typescript-eslint/no-unused-vars */ +import path from 'path' import type { HTTPMethod, LocalHook } from 'elysia' import { Kind, type TSchema } from '@sinclair/typebox' @@ -282,6 +283,7 @@ export const registerSchemaPath = ({ export const filterPaths = ( paths: Record, + docsPath: string, { excludeStaticFile = true, exclude = [] @@ -292,6 +294,11 @@ export const filterPaths = ( ) => { const newPaths: Record = {} + // exclude docs path and OpenAPI json path + const excludePaths = [`/${docsPath}`, `/${docsPath}/json`].map((p) => + path.normalize(p) + ) + for (const [key, value] of Object.entries(paths)) if ( !exclude.some((x) => { @@ -299,7 +306,7 @@ export const filterPaths = ( return x.test(key) }) && - !key.includes('/swagger') && + !excludePaths.includes(key) && !key.includes('*') && (excludeStaticFile ? !key.includes('.') : true) ) {