Skip to content

Commit 2340cbc

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

File tree

5 files changed

+288
-290
lines changed

5 files changed

+288
-290
lines changed

example/gen.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ export const app = new Elysia()
1414
})
1515
})
1616
)
17+
.model({
18+
'character.name': t.String(),
19+
'character.thing': t.Object({
20+
name: t.String()
21+
})
22+
})
1723
.get(
1824
'/const',
1925
() =>
2026
({
2127
name: 'Lilith',
2228
friends: ['Sartre', 'Fouco']
23-
}) as const
29+
})
2430
)
25-
.model({
26-
'character.name': t.String(),
27-
'character.thing': t.Object({
28-
name: t.String()
29-
})
30-
})
3131
.get(
3232
'/',
3333
() =>

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.8-beta.0",
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,15 +321,14 @@ export const fromTypes =
321321
)
322322
)
323323

324-
const routesString = extractRootObjects(instance)[0].replace(
325-
matchStatus,
326-
'"$1":'
324+
const routesString = extractRootObjects(
325+
instance.replace(matchStatus, '"$1":')
327326
)
328327

329328
const routes: AdditionalReference = {}
330329

331330
// Treaty is a collection of { ... } & { ... } & { ... }
332-
for (const route of extractRootObjects(routesString)) {
331+
for (const route of routesString) {
333332
let schema = TypeBox(route.replaceAll(/readonly/g, ''))
334333
if (schema.type !== 'object') continue
335334

src/openapi.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
ElysiaOpenAPIConfig,
1111
MapJsonSchema
1212
} from './types'
13-
import { DefaultErrorFunction } from '@sinclair/typebox/errors'
1413

1514
export const capitalize = (word: string) =>
1615
word.charAt(0).toUpperCase() + word.slice(1)
@@ -534,7 +533,7 @@ export function toOpenAPISchema(
534533
type === 'void' ||
535534
type === 'null' ||
536535
type === 'undefined'
537-
? (response as any)
536+
? ({ type, description } as any)
538537
: type === 'string' ||
539538
type === 'number' ||
540539
type === 'integer' ||
@@ -570,7 +569,7 @@ export function toOpenAPISchema(
570569
type === 'void' ||
571570
type === 'null' ||
572571
type === 'undefined'
573-
? (response as any)
572+
? ({ type, description } as any)
574573
: type === 'string' ||
575574
type === 'number' ||
576575
type === 'integer' ||

0 commit comments

Comments
 (0)