Skip to content

Commit 5e58a60

Browse files
committed
🎉 feat: refactor
1 parent eb790a2 commit 5e58a60

File tree

15 files changed

+769
-942
lines changed

15 files changed

+769
-942
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# 1.3.1
1+
# 1.3.2 - 22 Aug 2025
2+
Feature:
3+
- add `withHeader` for adding custom headers to response schema
4+
- spread all possible path for optional params
5+
6+
Breaking change:
7+
- rename `@elysiajs/swagger` to `@elysiajs/openapi`
8+
- map all `swagger`, and `scalar` prefix to respective `swagger` and `scalar` properties
9+
- rename `swaggerConfig`, and `scalarConfig` to `swagger` and `scalar` respectively
10+
- map `excludePaths`, `excludeMethods`, `excludeTags`, `excludeStaticFiles` to property of `excludes`
11+
12+
# 1.3.1 - 28 Jun 2025
213
Bug fix:
314
- Using relative path for specPath
415

bun.lock

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
"name": "@elysiajs/swagger",
66
"dependencies": {
77
"@scalar/themes": "^0.9.52",
8-
"@scalar/types": "^0.0.12",
98
"openapi-types": "^12.1.3",
10-
"pathe": "^1.1.2",
119
},
1210
"devDependencies": {
1311
"@apidevtools/swagger-parser": "^10.1.0",
12+
"@scalar/types": "^0.0.12",
1413
"@types/bun": "1.1.14",
1514
"elysia": "1.3.0-exp.71",
1615
"eslint": "9.6.0",
@@ -373,8 +372,6 @@
373372

374373
"path-scurry": ["[email protected]", "", { "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" } }, "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA=="],
375374

376-
"pathe": ["[email protected]", "", {}, "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ=="],
377-
378375
"picocolors": ["[email protected]", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="],
379376

380377
"picomatch": ["[email protected]", "", {}, "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg=="],

example/index.ts

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import { Elysia, t } from 'elysia'
2-
import { swagger } from '../src/index'
2+
import { openapi, withHeaders } from '../src/index'
33

44
const schema = t.Object({
55
test: t.Literal('hello')
66
})
77

8-
const app = new Elysia({ prefix: '/api' })
8+
const schema2 = t.Object({
9+
test: t.Literal('world')
10+
})
11+
12+
const user = t.Object({
13+
name: t.String({
14+
example: 'saltyaom'
15+
})
16+
})
17+
18+
const app = new Elysia()
919
.use(
10-
swagger({
20+
openapi({
1121
provider: 'scalar',
1222
documentation: {
1323
info: {
1424
title: 'Elysia Scalar',
15-
version: '0.8.1'
25+
version: '1.3.1a'
1626
},
1727
tags: [
1828
{
@@ -21,39 +31,55 @@ const app = new Elysia({ prefix: '/api' })
2131
}
2232
],
2333
components: {
24-
schemas: {
25-
User: {
26-
description: 'string'
27-
}
28-
},
2934
securitySchemes: {
30-
JwtAuth: {
35+
bearer: {
3136
type: 'http',
32-
scheme: 'bearer',
33-
bearerFormat: 'JWT',
34-
description: 'Enter JWT Bearer token **_only_**'
37+
scheme: 'bearer'
38+
},
39+
cookie: {
40+
type: 'apiKey',
41+
in: 'cookie',
42+
name: 'session_id'
3543
}
3644
}
3745
}
38-
},
39-
swaggerOptions: {
40-
persistAuthorization: true
4146
}
4247
})
4348
)
44-
.model({ schema })
49+
.model({ schema, schema2, user })
4550
.get(
4651
'/',
47-
() => {
48-
return { test: 'hello' as const }
49-
},
52+
{ test: 'hello' as const },
53+
{
54+
response: {
55+
200: t.Object({
56+
test: t.Literal('hello')
57+
}),
58+
204: withHeaders(
59+
t.Void({
60+
title: 'Thing',
61+
description: 'Void response'
62+
}),
63+
{
64+
'X-Custom-Header': t.String()
65+
}
66+
)
67+
}
68+
}
69+
)
70+
.post(
71+
'/json',
72+
({ body }) => ({
73+
test: 'world'
74+
}),
5075
{
51-
response: 'schema'
76+
parse: ['json', 'formdata'],
77+
body: 'user',
78+
response: {
79+
200: 'schema',
80+
400: 'schema2'
81+
}
5282
}
5383
)
54-
.post('/json', ({ body }) => body, {
55-
parse: ['json', 'formdata'],
56-
body: 'schema',
57-
response: 'schema'
58-
})
84+
.get('/id/:id?/name/:name?', () => {})
5985
.listen(3000)

example/index2.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

example/index3.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

package.json

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@elysiajs/swagger",
3-
"version": "1.3.1",
4-
"description": "Plugin for Elysia to auto-generate Swagger page",
2+
"name": "@elysiajs/openapi",
3+
"version": "1.3.2",
4+
"description": "Plugin for Elysia to auto-generate OpenAPI documentation",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -17,15 +17,10 @@
1717
"import": "./dist/index.mjs",
1818
"require": "./dist/cjs/index.js"
1919
},
20-
"./types": {
21-
"types": "./dist/types.d.ts",
22-
"import": "./dist/types.mjs",
23-
"require": "./dist/cjs/types.js"
24-
},
25-
"./utils": {
26-
"types": "./dist/utils.d.ts",
27-
"import": "./dist/utils.mjs",
28-
"require": "./dist/cjs/utils.js"
20+
"./openapi": {
21+
"types": "./dist/openapi.d.ts",
22+
"import": "./dist/openapi.mjs",
23+
"require": "./dist/cjs/openapi.js"
2924
},
3025
"./scalar": {
3126
"types": "./dist/scalar/index.d.ts",
@@ -36,18 +31,35 @@
3631
"types": "./dist/scalar/theme.d.ts",
3732
"import": "./dist/scalar/theme.mjs",
3833
"require": "./dist/cjs/scalar/theme.js"
34+
},
35+
"./swagger": {
36+
"types": "./dist/swagger/index.d.ts",
37+
"import": "./dist/swagger/index.mjs",
38+
"require": "./dist/cjs/swagger/index.js"
39+
},
40+
"./swagger/types": {
41+
"types": "./dist/swagger/types.d.ts",
42+
"import": "./dist/swagger/types.mjs",
43+
"require": "./dist/cjs/swagger/types.js"
44+
},
45+
"./types": {
46+
"types": "./dist/types.d.ts",
47+
"import": "./dist/types.mjs",
48+
"require": "./dist/cjs/types.js"
3949
}
4050
},
4151
"keywords": [
4252
"elysia",
43-
"swagger"
53+
"openapi",
54+
"swagger",
55+
"scalar"
4456
],
45-
"homepage": "https://github.com/elysiajs/elysia-swagger",
57+
"homepage": "https://github.com/elysiajs/elysia-openapi",
4658
"repository": {
4759
"type": "git",
48-
"url": "https://github.com/elysiajs/elysia-swagger"
60+
"url": "https://github.com/elysiajs/elysia-openapi"
4961
},
50-
"bugs": "https://github.com/elysiajs/elysia-swagger/issues",
62+
"bugs": "https://github.com/elysiajs/elysia-openapi/issues",
5163
"license": "MIT",
5264
"scripts": {
5365
"dev": "bun run --watch example/index.ts",
@@ -62,15 +74,14 @@
6274
"devDependencies": {
6375
"@apidevtools/swagger-parser": "^10.1.0",
6476
"@types/bun": "1.1.14",
77+
"@scalar/types": "^0.0.12",
6578
"elysia": "1.3.0-exp.71",
6679
"eslint": "9.6.0",
6780
"tsup": "^8.1.0",
6881
"typescript": "^5.5.3"
6982
},
7083
"dependencies": {
7184
"@scalar/themes": "^0.9.52",
72-
"@scalar/types": "^0.0.12",
73-
"openapi-types": "^12.1.3",
74-
"pathe": "^1.1.2"
85+
"openapi-types": "^12.1.3"
7586
}
7687
}

0 commit comments

Comments
 (0)