Skip to content

Commit b239366

Browse files
committed
🧹 chore(type-gen): handle array delimiter correctly
1 parent c0b16e6 commit b239366

File tree

4 files changed

+54
-51
lines changed

4 files changed

+54
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.4.8 - 21 Sep 2025
2+
Improvement:
3+
- type gen: handle array delimiter correctly
4+
15
# 1.4.7 - 21 Sep 2025
26
Improvement:
37
- type gen: remove readonly from generated type to fix readonly tuple

example/gen.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,60 @@ export const app = new Elysia()
1414
})
1515
})
1616
)
17+
.get(
18+
'/const',
19+
() =>
20+
({
21+
name: 'Lilith',
22+
friends: ['Sartre', 'Fouco']
23+
}) as const
24+
)
1725
.model({
1826
'character.name': t.String(),
1927
'character.thing': t.Object({
2028
name: t.String()
2129
})
2230
})
2331
.get(
24-
'/const',
32+
'/',
2533
() =>
26-
({
27-
name: 'Lilith',
28-
friends: ['Sartre', 'Fouco']
34+
({ test: 'hello' as const }) as any as
35+
| { test: 'hello' }
36+
| undefined,
37+
{
38+
response: {
39+
204: withHeaders(
40+
t.Void({
41+
title: 'Thing',
42+
description: 'Void response'
43+
}),
44+
{
45+
'X-Custom-Header': t.Literal('Elysia')
46+
}
47+
)
48+
}
49+
}
50+
)
51+
.post(
52+
'/json',
53+
({ body, status }) => (Math.random() > 0.5 ? status(418) : body),
54+
{
55+
body: t.Object({
56+
hello: t.String()
57+
})
58+
}
59+
)
60+
.get('/id/:id/name/:name', ({ params }) => params)
61+
.post(
62+
'/character',
63+
() => ({
64+
name: 'Lilith' as const
65+
}),
66+
{
67+
body: 'character.name',
68+
response: z.object({
69+
name: z.literal('Lilith')
2970
})
71+
}
3072
)
31-
// .get(
32-
// '/',
33-
// () =>
34-
// ({ test: 'hello' as const }) as any as
35-
// | { test: 'hello' }
36-
// | undefined,
37-
// {
38-
// response: {
39-
// 204: withHeaders(
40-
// t.Void({
41-
// title: 'Thing',
42-
// description: 'Void response'
43-
// }),
44-
// {
45-
// 'X-Custom-Header': t.Literal('Elysia')
46-
// }
47-
// )
48-
// }
49-
// }
50-
// )
51-
// .post(
52-
// '/json',
53-
// ({ body, status }) => (Math.random() > 0.5 ? status(418) : body),
54-
// {
55-
// body: t.Object({
56-
// hello: t.String()
57-
// })
58-
// }
59-
// )
60-
// .get('/id/:id/name/:name', ({ params }) => params)
61-
// .post(
62-
// '/character',
63-
// () => ({
64-
// name: 'Lilith' as const
65-
// }),
66-
// {
67-
// body: 'character.name',
68-
// response: z.object({
69-
// name: z.literal('Lilith')
70-
// })
71-
// }
72-
// )
7373
.listen(3000)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/openapi",
3-
"version": "1.4.7",
3+
"version": "1.4.8",
44
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",

src/gen/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,9 @@ export const fromTypes =
321321
)
322322
)
323323

324-
const routesString = wrapStatusInQuote(
325-
// Intentionally not adding "}"
326-
// to avoid mismatched bracket in loop below
327-
instance.slice(3, instance.indexOf('}, {', 4))
324+
const routesString = extractRootObjects(instance)[0].replace(
325+
matchStatus,
326+
'"$1":'
328327
)
329328

330329
const routes: AdditionalReference = {}

0 commit comments

Comments
 (0)