Skip to content

Commit 01b4d6a

Browse files
committed
🔧 fix(type-gen): match special, ad non-english character
1 parent ae3807a commit 01b4d6a

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
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.9 - 21 Sep 2025
2+
Improvement:
3+
- type gen: match special, ad non-english character
4+
15
# 1.4.8 - 21 Sep 2025
26
Improvement:
37
- type gen: handle array delimiter correctly

example/gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ export const app = new Elysia()
7070
})
7171
}
7272
)
73+
.get('/no-manual', () => ({
74+
name: 'lilith'
75+
}))
7376
.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.8",
3+
"version": "1.4.9",
44
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",

src/gen/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ function extractRootObjects(code: string) {
9090
const colonIdx = code.indexOf(':', i)
9191
if (colonIdx === -1) break
9292

93-
// backtrack to find the key (simple word characters)
93+
// --- find key ---
94+
// walk backwards from colon to find start of key
9495
let keyEnd = colonIdx - 1
9596
while (keyEnd >= 0 && /\s/.test(code[keyEnd])) keyEnd--
97+
9698
let keyStart = keyEnd
97-
while (keyStart >= 0 && /\w/.test(code[keyStart])) keyStart--
99+
// keep going back until we hit a delimiter (whitespace, brace, semicolon, comma, or start of file)
100+
while (keyStart >= 0 && !/[\s{};,\n]/.test(code[keyStart])) {
101+
keyStart--
102+
}
98103

99104
// find the opening brace after colon
100105
const braceIdx = code.indexOf('{', colonIdx)
@@ -321,14 +326,12 @@ export const fromTypes =
321326
)
322327
)
323328

324-
const routesString = extractRootObjects(
325-
instance.replace(matchStatus, '"$1":')
326-
)
327-
328329
const routes: AdditionalReference = {}
329330

330331
// Treaty is a collection of { ... } & { ... } & { ... }
331-
for (const route of routesString) {
332+
for (const route of extractRootObjects(
333+
instance.slice(2).replace(matchStatus, '"$1":')
334+
)) {
332335
let schema = TypeBox(route.replaceAll(/readonly/g, ''))
333336
if (schema.type !== 'object') continue
334337

0 commit comments

Comments
 (0)