Skip to content

Commit 1a78ff0

Browse files
feat: add support for .all() & filter out non-openapi methods
1 parent 5303809 commit 1a78ff0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,29 @@ export const swagger = async <Path extends string = '/swagger'>(
109109
const routes = app.getGlobalRoutes() as InternalRoute[]
110110

111111
if (routes.length !== totalRoutes) {
112+
const ALLOWED_METHODS = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE']
112113
totalRoutes = routes.length
113114

114115
routes.forEach((route: InternalRoute) => {
115116
if (route.hooks?.detail?.hide === true) return
116117
// TODO: route.hooks?.detail?.hide !== false add ability to hide: false to prevent excluding
117118
if (excludeMethods.includes(route.method)) return
119+
if (ALLOWED_METHODS.includes(route.method) === false && route.method !== 'ALL') return
120+
121+
if (route.method === 'ALL') {
122+
ALLOWED_METHODS.forEach((method) => {
123+
registerSchemaPath({
124+
schema,
125+
hook: route.hooks,
126+
method,
127+
path: route.path,
128+
// @ts-ignore
129+
models: app.definitions?.type,
130+
contentType: route.hooks.type
131+
})
132+
})
133+
return
134+
}
118135

119136
registerSchemaPath({
120137
schema,

0 commit comments

Comments
 (0)