diff --git a/README.md b/README.md index 6d8bf1b..45d0fe2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ bun add @elysiajs/swagger ## Example ```typescript -import { Elysia } from 'elysia' +import { Elysia, t } from 'elysia' import { swagger } from '@elysiajs/swagger' const app = new Elysia() diff --git a/src/index.ts b/src/index.ts index cc9cb55..9f380b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,8 @@ export const swagger = exclude = [], swaggerOptions = {}, theme = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`, - autoDarkMode = true + autoDarkMode = true, + excludeMethods = ['OPTIONS'] }: ElysiaSwaggerConfig = { provider: 'scalar', scalarVersion: '1.12.5', @@ -39,7 +40,8 @@ export const swagger = path: '/swagger' as Path, exclude: [], swaggerOptions: {}, - autoDarkMode: true + autoDarkMode: true, + excludeMethods: ['OPTIONS'] } ) => (app: Elysia) => { @@ -105,6 +107,8 @@ export const swagger = totalRoutes = routes.length routes.forEach((route: InternalRoute) => { + if (excludeMethods.includes(route.method)) return + registerSchemaPath({ schema, hook: route.hooks, diff --git a/src/types.ts b/src/types.ts index 9ca1876..a137917 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,4 +100,9 @@ export interface ElysiaSwaggerConfig { * Using poor man dark mode 😭 */ autoDarkMode?: boolean + + /** + * Exclude methods from Swagger + */ + excludeMethods?: string[] }