🎉 feat: user provided components

This commit is contained in:
saltyaom
2023-08-17 15:40:07 +07:00
4 changed files with 61 additions and 47 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -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)

View File

@@ -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"

View File

@@ -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<any>) => {
registerSchemaPath({
schema,
hook: route.hooks,
method: route.method,
path: route.path,
models: app.meta.defs,
contentType: route.hooks.type
})
routes.forEach((route: InternalRoute<any>) => {
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