fix: document path not excluded

This commit is contained in:
findmio
2024-05-15 19:03:47 +08:00
parent ff6e88ec29
commit 6f2fbd14e8
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ export const swagger =
...documentation.info
}
},
paths: {...filterPaths(schema, {
paths: {...filterPaths(schema, relativePath, {
excludeStaticFile,
exclude: Array.isArray(exclude) ? exclude : [exclude]
}),
+8 -1
View File
@@ -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<string, any>,
docsPath: string,
{
excludeStaticFile = true,
exclude = []
@@ -292,6 +294,11 @@ export const filterPaths = (
) => {
const newPaths: Record<string, any> = {}
// 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)
) {