Skip to content

Commit c0b16e6

Browse files
committed
🧹 chore(type-gen): remove readonly from generated type to fix readonly tuple
1 parent 8169471 commit c0b16e6

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
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.7 - 21 Sep 2025
2+
Improvement:
3+
- type gen: remove readonly from generated type to fix readonly tuple
4+
15
# 1.4.6 - 21 Sep 2025
26
Bug fix:
37
- type gen: handle inline 200 response schema assignment

example/gen.ts

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,53 @@ export const app = new Elysia()
2121
})
2222
})
2323
.get(
24-
'/',
24+
'/const',
2525
() =>
26-
({ test: 'hello' as const }) as any as
27-
| { test: 'hello' }
28-
| undefined,
29-
{
30-
response: {
31-
204: withHeaders(
32-
t.Void({
33-
title: 'Thing',
34-
description: 'Void response'
35-
}),
36-
{
37-
'X-Custom-Header': t.Literal('Elysia')
38-
}
39-
)
40-
}
41-
}
42-
)
43-
.post(
44-
'/json',
45-
({ body, status }) => (Math.random() > 0.5 ? status(418) : body),
46-
{
47-
body: t.Object({
48-
hello: t.String()
49-
})
50-
}
51-
)
52-
.get('/id/:id/name/:name', ({ params }) => params)
53-
.post(
54-
'/character',
55-
() => ({
56-
name: 'Lilith' as const
57-
}),
58-
{
59-
body: 'character.name',
60-
response: z.object({
61-
name: z.literal('Lilith')
26+
({
27+
name: 'Lilith',
28+
friends: ['Sartre', 'Fouco']
6229
})
63-
}
6430
)
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+
// )
6573
.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.6",
3+
"version": "1.4.7",
44
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",

src/gen/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ export const fromTypes =
295295

296296
const declaration = readFileSync(targetFile, 'utf8')
297297

298-
// console.log(declaration, targetFile)
299-
300298
// Check just in case of race-condition
301299
if (!debug && existsSync(tmpRoot))
302300
rmSync(tmpRoot, { recursive: true, force: true })
@@ -333,7 +331,7 @@ export const fromTypes =
333331

334332
// Treaty is a collection of { ... } & { ... } & { ... }
335333
for (const route of extractRootObjects(routesString)) {
336-
let schema = TypeBox(route)
334+
let schema = TypeBox(route.replaceAll(/readonly/g, ''))
337335
if (schema.type !== 'object') continue
338336

339337
const paths = []

0 commit comments

Comments
 (0)