diff --git a/src/index.ts b/src/index.ts index 2a1a284..684c9a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,8 +15,8 @@ import type { ElysiaSwaggerConfig } from './types' * * @see https://github.com/elysiajs/elysia-swagger */ -export const swagger = async ( - { +export const swagger = async ({ + slug = "/", //api/ provider = 'scalar', scalarVersion = 'latest', scalarCDN = '', @@ -24,7 +24,7 @@ export const swagger = async ( documentation = {}, version = '5.9.0', excludeStaticFile = true, - path = '/swagger' as Path, + path = 'swagger' as Path, exclude = [], swaggerOptions = {}, theme = `https://unpkg.com/swagger-ui-dist@${version}/swagger-ui.css`, @@ -32,6 +32,7 @@ export const swagger = async ( excludeMethods = ['OPTIONS'], excludeTags = [] }: ElysiaSwaggerConfig = { + slug: "/", // api/ -> Forexample provider: 'scalar', scalarVersion: 'latest', scalarCDN: '', @@ -39,7 +40,7 @@ export const swagger = async ( documentation: {}, version: '5.9.0', excludeStaticFile: true, - path: '/swagger' as Path, + path: 'swagger' as Path, exclude: [], swaggerOptions: {}, autoDarkMode: true, @@ -59,8 +60,7 @@ export const swagger = async ( version: '0.0.0', ...documentation.info } - - const relativePath = path.startsWith('/') ? path.slice(1) : path + const relativePath = (slug + path).startsWith('/') ? path.slice(1) : path const app = new Elysia({ name: '@elysiajs/swagger' }) diff --git a/src/types.ts b/src/types.ts index 5370e38..c20657f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,14 @@ export interface ElysiaSwaggerConfig { * @see https://github.com/swagger-api/swagger-ui */ provider?: 'scalar' | 'swagger-ui' + /** + * Base route for framework integrations + * + * @default '/' + * @see https://github.com/scalar/scalar + * @see https://github.com/swagger-api/swagger-ui + */ + slug?: string /** * Version to use for Scalar cdn bundle *