Skip to content

Commit 6953d2b

Browse files
committed
🔧 fix(type generator): imbalance bracket or something
1 parent a8455fe commit 6953d2b

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# 1.3.7
1+
# 1.3.7 - 3 Sep 2025
22
Improvement:
33
- type generator: clean up temp files after generation
4+
- type generator: imbalance bracket or something
45

56
# 1.3.6 - 3 Sep 2025
67
Improvement:

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.3.6",
3+
"version": "1.3.7",
44
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",

src/gen/index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { AdditionalReference, AdditionalReferences } from '../types'
1717
import { Kind, TObject } from '@sinclair/typebox/type'
1818

1919
const matchRoute = /: Elysia<(.*)>/gs
20-
const matchStatus = /(\d{3}):/gs
20+
const matchStatus = /(\d{3}):/g
2121
const wrapStatusInQuote = (value: string) => value.replace(matchStatus, '"$1":')
2222

2323
const exec = (command: string, cwd: string) =>
@@ -156,13 +156,19 @@ export const fromTypes =
156156
// 1 2 3 4 5
157157
// We want the 4th one
158158
for (let i = 0; i < 3; i++)
159-
instance = instance.slice(instance.indexOf('}, {', 3))
159+
instance = instance.slice(
160+
instance.indexOf(
161+
'}, {',
162+
// remove just `}, `, leaving `{`
163+
3
164+
)
165+
)
160166

161-
const routesString =
162-
wrapStatusInQuote(instance).slice(
163-
3,
164-
instance.indexOf('}, {', 3)
165-
) + '}\n}\n'
167+
const routesString = wrapStatusInQuote(
168+
// Intentionally not adding "}"
169+
// to avoid mismatched bracket in loop below
170+
instance.slice(3, instance.indexOf('}, {', 4))
171+
)
166172

167173
const routes: AdditionalReference = {}
168174

@@ -171,13 +177,8 @@ export const fromTypes =
171177
// instead of being nested in a route object
172178
for (const route of routesString.slice(1).split('} & {')) {
173179
// as '} & {' is removed, we need to add it back
174-
let schema = TypeBox(`{${route}}}`)
175-
if (schema.type !== 'object') {
176-
// just in case
177-
schema = TypeBox(`{${route}}`)
178-
179-
if (schema.type !== 'object') continue
180-
}
180+
let schema = TypeBox(`{${route}}`)
181+
if (schema.type !== 'object') continue
181182

182183
const paths = []
183184

0 commit comments

Comments
 (0)