Skip to content

Commit 22d4ea2

Browse files
committed
Fix exclude option regression (methods normalization + regex support)
Refactors the exclusion of HTTP methods to ensure case-insensitive matching and supports RegExp for excluded paths.
1 parent 0d9fa40 commit 22d4ea2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/openapi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ export function toOpenAPISchema(
205205
vendors?: MapJsonSchema
206206
) {
207207
const {
208-
methods: excludeMethods = ['OPTIONS'],
209208
staticFile: excludeStaticFile = true,
210209
tags: excludeTags
211210
} = exclude ?? {}
@@ -216,6 +215,8 @@ export function toOpenAPISchema(
216215
? [exclude.paths]
217216
: []
218217

218+
const excludeMethods = exclude?.methods?.map((method) => method.toLowerCase()) ?? ['options']
219+
219220
const paths: OpenAPIV3.PathsObject = Object.create(null)
220221
// @ts-ignore
221222
const definitions = app.getGlobalDefinitions?.().type
@@ -240,7 +241,11 @@ export function toOpenAPISchema(
240241

241242
if (
242243
(excludeStaticFile && route.path.includes('.')) ||
243-
excludePaths.includes(route.path) ||
244+
excludePaths.some((excludedPath) =>
245+
excludedPath instanceof RegExp
246+
? excludedPath.test(route.path)
247+
: excludedPath === route.path
248+
) ||
244249
excludeMethods.includes(method)
245250
)
246251
continue

0 commit comments

Comments
 (0)