mirror of
https://github.com/zoriya/elysia-swagger.git
synced 2026-06-01 21:35:21 +00:00
Merge pull request #123 from findmio/fix/docs-path
fix: document path not excluded
This commit is contained in:
+1
-1
@@ -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
@@ -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)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user