Skip to content

Commit

Permalink
Merge pull request #123 from findmio/fix/docs-path
Browse files Browse the repository at this point in the history
fix: document path not excluded
  • Loading branch information
marclave committed May 19, 2024
2 parents ff6e88e + 6f2fbd1 commit 5cb3fa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const swagger =
...documentation.info
}
},
paths: {...filterPaths(schema, {
paths: {...filterPaths(schema, relativePath, {
excludeStaticFile,
exclude: Array.isArray(exclude) ? exclude : [exclude]
}),
Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -282,6 +283,7 @@ export const registerSchemaPath = ({

export const filterPaths = (
paths: Record<string, any>,
docsPath: string,
{
excludeStaticFile = true,
exclude = []
Expand All @@ -292,14 +294,19 @@ 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) => {
if (typeof x === 'string') return key === x

return x.test(key)
}) &&
!key.includes('/swagger') &&
!excludePaths.includes(key) &&
!key.includes('*') &&
(excludeStaticFile ? !key.includes('.') : true)
) {
Expand Down

0 comments on commit 5cb3fa0

Please sign in to comment.