diff --git a/bun.lockb b/bun.lockb index 19fcefc..d51aa65 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/example/index.ts b/example/index.ts index 9fcc6ec..bbb9d3b 100644 --- a/example/index.ts +++ b/example/index.ts @@ -10,18 +10,31 @@ const app = new Elysia({ documentation: { info: { title: 'Elysia', - version: '0.5.0' + version: '0.6.10' }, tags: [ { name: 'Test', description: 'Hello' } - ] + ], + components: { + schemas: { + User: { + description: 'string' + } + }, + securitySchemes: { + JwtAuth: { + type: 'http', + scheme: 'bearer', + bearerFormat: 'JWT', + description: 'Enter JWT Bearer token **_only_**' + } + } + } } }) ) .use(plugin) .listen(8080) - -console.log(app.routes) \ No newline at end of file diff --git a/package.json b/package.json index e16b0b2..2e8f15b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@elysiajs/swagger", - "version": "0.6.0", + "version": "0.6.1", "description": "Plugin for Elysia to auto-generate Swagger page", "author": { "name": "saltyAom", @@ -35,12 +35,13 @@ "release": "npm run build && npm run test && npm publish --access public" }, "peerDependencies": { - "elysia": ">= 0.6.0" + "elysia": ">= 0.6.7" }, "devDependencies": { + "@types/lodash.clonedeep": "^4.5.7", "@types/node": "^20.1.4", "bun-types": "^0.7.0", - "elysia": "0.6.8", + "elysia": "^0.6.10", "eslint": "^8.40.0", "rimraf": "4.3", "typescript": "^5.0.4" diff --git a/src/index.ts b/src/index.ts index 6ddfe94..37615aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,50 +74,50 @@ export const swagger = } } ) - }).route( - 'GET', - `${path}/json`, - () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const routes = app.routes as InternalRoute[] + }).route('GET', `${path}/json`, () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const routes = app.routes as InternalRoute[] - if (routes.length !== totalRoutes) { - totalRoutes = routes.length + if (routes.length !== totalRoutes) { + totalRoutes = routes.length - routes.forEach((route: InternalRoute) => { - registerSchemaPath({ - schema, - hook: route.hooks, - method: route.method, - path: route.path, - models: app.meta.defs, - contentType: route.hooks.type - }) + routes.forEach((route: InternalRoute) => { + registerSchemaPath({ + schema, + hook: route.hooks, + method: route.method, + path: route.path, + models: app.meta.defs, + contentType: route.hooks.type }) - } - - return { - openapi: '3.0.3', - ...{ - ...documentation, - info: { - title: 'Elysia Documentation', - description: 'Developement documentation', - version: '0.0.0', - ...documentation.info - } - }, - paths: filterPaths(schema, { - excludeStaticFile, - exclude: Array.isArray(exclude) ? exclude : [exclude] - }), - components: { - schemas: app.meta.defs - } - } satisfies OpenAPIV3.Document + }) } - ) + + return { + openapi: '3.0.3', + ...{ + ...documentation, + info: { + title: 'Elysia Documentation', + description: 'Developement documentation', + version: '0.0.0', + ...documentation.info + } + }, + paths: filterPaths(schema, { + excludeStaticFile, + exclude: Array.isArray(exclude) ? exclude : [exclude] + }), + components: { + ...documentation.components, + schemas: { + ...app.meta.defs, + ...documentation.components?.schemas + } + } + } satisfies OpenAPIV3.Document + }) // This is intentional to prevent deeply nested type return app