From 6f2fbd14e8553931aab229c349adb4f234c9f8ea Mon Sep 17 00:00:00 2001 From: findmio Date: Wed, 15 May 2024 19:03:47 +0800 Subject: [PATCH 1/3] fix: document path not excluded --- src/index.ts | 2 +- src/utils.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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) ) { From eddaf62eaa1189a5cf199dbc9734b78e37c38e80 Mon Sep 17 00:00:00 2001 From: zoto_ff <142039751+zoto-ff@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:28:39 +0300 Subject: [PATCH 2/3] export ElysiaSwaggerConfig --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index ea13308..81bf4f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -169,3 +169,4 @@ export const swagger = } export default swagger +export { ElysiaSwaggerConfig } From 23dc059bdfa9be667be978264b6c34fc6d38a89d Mon Sep 17 00:00:00 2001 From: zoto_ff <142039751+zoto-ff@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:31:09 +0300 Subject: [PATCH 3/3] export type --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 81bf4f2..9dcce5f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -169,4 +169,4 @@ export const swagger = } export default swagger -export { ElysiaSwaggerConfig } +export type { ElysiaSwaggerConfig }