From 1a78ff051ff2c37e7cf3248ef099daa4a1cd05f2 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Aug 2024 13:46:49 -0500 Subject: [PATCH] feat: add support for .all() & filter out non-openapi methods --- src/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/index.ts b/src/index.ts index 4b6cff6..7fdb2c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -109,12 +109,29 @@ export const swagger = async ( const routes = app.getGlobalRoutes() as InternalRoute[] if (routes.length !== totalRoutes) { + const ALLOWED_METHODS = ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH', 'TRACE'] totalRoutes = routes.length routes.forEach((route: InternalRoute) => { if (route.hooks?.detail?.hide === true) return // TODO: route.hooks?.detail?.hide !== false add ability to hide: false to prevent excluding if (excludeMethods.includes(route.method)) return + if (ALLOWED_METHODS.includes(route.method) === false && route.method !== 'ALL') return + + if (route.method === 'ALL') { + ALLOWED_METHODS.forEach((method) => { + registerSchemaPath({ + schema, + hook: route.hooks, + method, + path: route.path, + // @ts-ignore + models: app.definitions?.type, + contentType: route.hooks.type + }) + }) + return + } registerSchemaPath({ schema,