Skip to content

Commit 055fa57

Browse files
committed
🎉 feat: user provided components
2 parents ed03160 + 103b041 commit 055fa57

File tree

4 files changed

+60
-46
lines changed

4 files changed

+60
-46
lines changed

bun.lockb

1.18 KB
Binary file not shown.

example/index.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ const app = new Elysia({
1010
documentation: {
1111
info: {
1212
title: 'Elysia',
13-
version: '0.5.0'
13+
version: '0.6.10'
1414
},
1515
tags: [
1616
{
1717
name: 'Test',
1818
description: 'Hello'
1919
}
20-
]
20+
],
21+
components: {
22+
schemas: {
23+
User: {
24+
description: 'string'
25+
}
26+
},
27+
securitySchemes: {
28+
JwtAuth: {
29+
type: 'http',
30+
scheme: 'bearer',
31+
bearerFormat: 'JWT',
32+
description: 'Enter JWT Bearer token **_only_**'
33+
}
34+
}
35+
}
2136
}
2237
})
2338
)
2439
.use(plugin)
2540
.listen(8080)
26-
27-
console.log(app.routes)

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/swagger",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Plugin for Elysia to auto-generate Swagger page",
55
"author": {
66
"name": "saltyAom",
@@ -35,12 +35,13 @@
3535
"release": "npm run build && npm run test && npm publish --access public"
3636
},
3737
"peerDependencies": {
38-
"elysia": ">= 0.6.0"
38+
"elysia": ">= 0.6.7"
3939
},
4040
"devDependencies": {
41+
"@types/lodash.clonedeep": "^4.5.7",
4142
"@types/node": "^20.1.4",
4243
"bun-types": "^0.7.0",
43-
"elysia": "0.6.8",
44+
"elysia": "^0.6.10",
4445
"eslint": "^8.40.0",
4546
"rimraf": "4.3",
4647
"typescript": "^5.0.4"

src/index.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,50 +74,50 @@ export const swagger =
7474
}
7575
}
7676
)
77-
}).route(
78-
'GET',
79-
`${path}/json`,
80-
() => {
81-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
82-
// @ts-ignore
83-
const routes = app.routes as InternalRoute[]
77+
}).route('GET', `${path}/json`, () => {
78+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
79+
// @ts-ignore
80+
const routes = app.routes as InternalRoute[]
8481

85-
if (routes.length !== totalRoutes) {
86-
totalRoutes = routes.length
82+
if (routes.length !== totalRoutes) {
83+
totalRoutes = routes.length
8784

88-
routes.forEach((route: InternalRoute<any>) => {
89-
registerSchemaPath({
90-
schema,
91-
hook: route.hooks,
92-
method: route.method,
93-
path: route.path,
94-
models: app.meta.defs,
95-
contentType: route.hooks.type
96-
})
85+
routes.forEach((route: InternalRoute<any>) => {
86+
registerSchemaPath({
87+
schema,
88+
hook: route.hooks,
89+
method: route.method,
90+
path: route.path,
91+
models: app.meta.defs,
92+
contentType: route.hooks.type
9793
})
98-
}
94+
})
95+
}
9996

100-
return {
101-
openapi: '3.0.3',
102-
...{
103-
...documentation,
104-
info: {
105-
title: 'Elysia Documentation',
106-
description: 'Developement documentation',
107-
version: '0.0.0',
108-
...documentation.info
109-
}
110-
},
111-
paths: filterPaths(schema, {
112-
excludeStaticFile,
113-
exclude: Array.isArray(exclude) ? exclude : [exclude]
114-
}),
115-
components: {
116-
schemas: app.meta.defs
97+
return {
98+
openapi: '3.0.3',
99+
...{
100+
...documentation,
101+
info: {
102+
title: 'Elysia Documentation',
103+
description: 'Developement documentation',
104+
version: '0.0.0',
105+
...documentation.info
117106
}
118-
} satisfies OpenAPIV3.Document
119-
}
120-
)
107+
},
108+
paths: filterPaths(schema, {
109+
excludeStaticFile,
110+
exclude: Array.isArray(exclude) ? exclude : [exclude]
111+
}),
112+
components: {
113+
...documentation.components,
114+
schemas: {
115+
...app.meta.defs,
116+
...documentation.components?.schemas
117+
}
118+
}
119+
} satisfies OpenAPIV3.Document
120+
})
121121

122122
// This is intentional to prevent deeply nested type
123123
return app

0 commit comments

Comments
 (0)