Skip to content

Commit 8c2050e

Browse files
committed
🔧 fix: any type
1 parent 47a5b26 commit 8c2050e

File tree

7 files changed

+172
-159
lines changed

7 files changed

+172
-159
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 0.7.1 - 20 Sep 2023
2+
Bug fix:
3+
- Add openapi-types as dependencies
4+
- Fix `any` returned type
5+
6+
# 0.7.0 - 20 Sep 2023
7+
- Add support for Elysia 0.
8+
9+
# 0.7.0-beta.0 - 18 Sep 2023
10+
- Add support for Elysia 0.7
11+
112
# 0.6.2 - 11 Sep 2023
213
- Ship lodash.cloneDeep type
314

bun.lockb

655 Bytes
Binary file not shown.

example/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const app = new Elysia({
1010
documentation: {
1111
info: {
1212
title: 'Elysia',
13-
version: '0.6.10'
13+
version: '0.7.0'
1414
},
1515
tags: [
1616
{

example/plugin.ts

Lines changed: 101 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,103 @@
11
import { Elysia, t } from 'elysia'
22

3-
export const plugin = (app: Elysia) =>
4-
app.group(
5-
'/a',
6-
(app) =>
7-
app
8-
.model({
9-
sign: t.Object(
10-
{
11-
username: t.String(),
12-
password: t.String()
13-
},
14-
{
15-
description: 'Models for handling authentication'
16-
}
17-
),
18-
number: t.Number()
19-
})
20-
.get('/', ({ set }) => 'hi', {
21-
detail: {
22-
summary: 'Ping Pong',
23-
description: 'Lorem Ipsum Dolar',
24-
tags: ['Test']
25-
}
26-
})
27-
.get('/unpath/:id', ({ params: { id } }) => id, {
28-
params: t.Object({
29-
id: t.String({
30-
description: 'Extract value from path parameter'
31-
})
32-
}),
33-
detail: {
34-
deprecated: true
35-
}
36-
})
37-
.post('/json', ({ body }) => body, {
38-
type: 'json',
39-
body: 'sign',
40-
response: {
41-
200: 'sign'
42-
},
43-
detail: {
44-
summary: 'Using reference model'
45-
}
46-
})
47-
// .post(
48-
// '/json/:id',
49-
// ({ body, params: { id }, query: { name } }) => ({
50-
// ...body,
51-
// id
52-
// }),
53-
// {
54-
// transform({ params }) {
55-
// params.id = +params.id
56-
// },
57-
// schema: {
58-
// body: 'sign',
59-
// params: t.Object({
60-
// id: t.Number()
61-
// }),
62-
// response: {
63-
// 200: t.Object(
64-
// {
65-
// id: t.Number(),
66-
// username: t.String(),
67-
// password: t.String()
68-
// },
69-
// {
70-
// title: 'User',
71-
// description:
72-
// "Contains user's confidential metadata"
73-
// }
74-
// ),
75-
// 400: t.Object({
76-
// error: t.String()
77-
// })
78-
// },
79-
// detail: {
80-
// summary: 'Transform path parameter'
81-
// }
82-
// }
83-
// }
84-
// )
85-
.post('/file', ({ body: { file } }) => file, {
86-
body: t.Object({
87-
file: t.File({
88-
type: ['image/jpeg', 'image/'],
89-
minSize: '1k',
90-
maxSize: '5m'
91-
})
92-
}),
93-
response: t.File()
94-
})
95-
// .post('/files', ({ body: { files } }) => files[0], {
96-
// schema: {
97-
// body: t.Object({
98-
// files: t.Files({
99-
// type: 'image',
100-
// maxSize: '5m'
101-
// })
102-
// }),
103-
// response: t.File()
104-
// }
105-
// })
106-
)
3+
export const plugin = new Elysia({
4+
prefix: '/a'
5+
})
6+
.model({
7+
sign: t.Object(
8+
{
9+
username: t.String(),
10+
password: t.String()
11+
},
12+
{
13+
description: 'Models for handling authentication'
14+
}
15+
),
16+
number: t.Number()
17+
})
18+
.get('/', ({ set }) => 'hi', {
19+
detail: {
20+
summary: 'Ping Pong',
21+
description: 'Lorem Ipsum Dolar',
22+
tags: ['Test']
23+
}
24+
})
25+
.get('/unpath/:id', ({ params: { id } }) => id, {
26+
params: t.Object({
27+
id: t.String({
28+
description: 'Extract value from path parameter'
29+
})
30+
}),
31+
detail: {
32+
deprecated: true
33+
}
34+
})
35+
.post('/json', ({ body }) => body, {
36+
type: 'json',
37+
body: 'sign',
38+
response: {
39+
200: 'sign'
40+
},
41+
detail: {
42+
summary: 'Using reference model'
43+
}
44+
})
45+
// .post(
46+
// '/json/:id',
47+
// ({ body, params: { id }, query: { name } }) => ({
48+
// ...body,
49+
// id
50+
// }),
51+
// {
52+
// transform({ params }) {
53+
// params.id = +params.id
54+
// },
55+
// schema: {
56+
// body: 'sign',
57+
// params: t.Object({
58+
// id: t.Number()
59+
// }),
60+
// response: {
61+
// 200: t.Object(
62+
// {
63+
// id: t.Number(),
64+
// username: t.String(),
65+
// password: t.String()
66+
// },
67+
// {
68+
// title: 'User',
69+
// description:
70+
// "Contains user's confidential metadata"
71+
// }
72+
// ),
73+
// 400: t.Object({
74+
// error: t.String()
75+
// })
76+
// },
77+
// detail: {
78+
// summary: 'Transform path parameter'
79+
// }
80+
// }
81+
// }
82+
// )
83+
.post('/file', ({ body: { file } }) => file, {
84+
body: t.Object({
85+
file: t.File({
86+
type: ['image/jpeg', 'image/'],
87+
minSize: '1k',
88+
maxSize: '5m'
89+
})
90+
}),
91+
response: t.File()
92+
})
93+
// .post('/files', ({ body: { files } }) => files[0], {
94+
// schema: {
95+
// body: t.Object({
96+
// files: t.Files({
97+
// type: 'image',
98+
// maxSize: '5m'
99+
// })
100+
// }),
101+
// response: t.File()
102+
// }
103+
// })

package.json

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
{
2-
"name": "@elysiajs/swagger",
3-
"version": "0.6.2",
4-
"description": "Plugin for Elysia to auto-generate Swagger page",
5-
"author": {
6-
"name": "saltyAom",
7-
"url": "https://github.com/SaltyAom",
8-
"email": "saltyaom@gmail.com"
9-
},
10-
"main": "./dist/index.js",
11-
"exports": {
12-
"bun": "./dist/index.js",
13-
"node": "./dist/cjs/index.js",
14-
"require": "./dist/cjs/index.js",
15-
"import": "./dist/index.js",
16-
"default": "./dist/index.js"
17-
},
18-
"types": "./src/index.ts",
19-
"keywords": [
20-
"elysia",
21-
"swagger"
22-
],
23-
"homepage": "https://github.com/elysiajs/elysia-swagger",
24-
"repository": {
25-
"type": "git",
26-
"url": "https://github.com/elysiajs/elysia-swagger"
27-
},
28-
"bugs": "https://github.com/elysiajs/elysia-swagger/issues",
29-
"license": "MIT",
30-
"scripts": {
31-
"dev": "bun run --watch example/index.ts",
32-
"test": "bun test && npm run test:node",
33-
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
34-
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
35-
"release": "npm run build && npm run test && npm publish --access public"
36-
},
37-
"peerDependencies": {
38-
"elysia": ">= 0.6.7"
39-
},
40-
"devDependencies": {
41-
"@types/node": "^20.1.4",
42-
"bun-types": "^0.7.0",
43-
"elysia": "^0.6.20",
44-
"eslint": "^8.40.0",
45-
"rimraf": "4.3",
46-
"typescript": "^5.0.4"
47-
},
48-
"dependencies": {
49-
"@types/lodash.clonedeep": "^4.5.7",
50-
"lodash.clonedeep": "^4.5.0"
51-
}
2+
"name": "@elysiajs/swagger",
3+
"version": "0.7.1",
4+
"description": "Plugin for Elysia to auto-generate Swagger page",
5+
"author": {
6+
"name": "saltyAom",
7+
"url": "https://github.com/SaltyAom",
8+
"email": "saltyaom@gmail.com"
9+
},
10+
"main": "./dist/index.js",
11+
"exports": {
12+
"bun": "./dist/index.js",
13+
"node": "./dist/cjs/index.js",
14+
"require": "./dist/cjs/index.js",
15+
"import": "./dist/index.js",
16+
"default": "./dist/index.js"
17+
},
18+
"types": "./src/index.ts",
19+
"keywords": [
20+
"elysia",
21+
"swagger"
22+
],
23+
"homepage": "https://github.com/elysiajs/elysia-swagger",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/elysiajs/elysia-swagger"
27+
},
28+
"bugs": "https://github.com/elysiajs/elysia-swagger/issues",
29+
"license": "MIT",
30+
"scripts": {
31+
"dev": "bun run --watch example/index.ts",
32+
"test": "bun test && npm run test:node",
33+
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
34+
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
35+
"release": "npm run build && npm run test && npm publish --access public"
36+
},
37+
"peerDependencies": {
38+
"elysia": ">= 0.7.0"
39+
},
40+
"devDependencies": {
41+
"@types/node": "^20.1.4",
42+
"bun-types": "^0.7.0",
43+
"elysia": "0.7.0",
44+
"eslint": "^8.40.0",
45+
"rimraf": "4.3",
46+
"typescript": "^5.0.4"
47+
},
48+
"dependencies": {
49+
"@types/lodash.clonedeep": "^4.5.7",
50+
"lodash.clonedeep": "^4.5.0",
51+
"openapi-types": "^12.1.3"
52+
}
5253
}

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,22 @@ export const swagger =
7474
}
7575
}
7676
)
77-
}).route('GET', `${path}/json`, () => {
77+
}).get(`${path}/json`, () => {
7878
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7979
// @ts-ignore
8080
const routes = app.routes as InternalRoute[]
8181

8282
if (routes.length !== totalRoutes) {
8383
totalRoutes = routes.length
8484

85-
routes.forEach((route: InternalRoute<any>) => {
85+
routes.forEach((route: InternalRoute) => {
8686
registerSchemaPath({
8787
schema,
8888
hook: route.hooks,
8989
method: route.method,
9090
path: route.path,
91-
models: app.meta.defs,
91+
// @ts-ignore
92+
models: app.definitions,
9293
contentType: route.hooks.type
9394
})
9495
})
@@ -112,7 +113,8 @@ export const swagger =
112113
components: {
113114
...documentation.components,
114115
schemas: {
115-
...app.meta.defs,
116+
// @ts-ignore
117+
...app.definitions,
116118
...documentation.components?.schemas
117119
}
118120
}

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ export const registerSchemaPath = ({
142142
Object.entries(responseSchema as Record<string, TSchema>).forEach(
143143
([key, value]) => {
144144
if (typeof value === 'string') {
145+
if(!models[value]) return
146+
145147
// eslint-disable-next-line @typescript-eslint/no-unused-vars
146148
const { type, properties, required, ...rest } = models[
147149
value

0 commit comments

Comments
 (0)