-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
Happens with [email protected] and @elysiajs/[email protected].
Manually specifying the response property is required to display the response type in OpenAPI; automatic type inference is completely unavailable.
For example:
// src/modules/project/index.ts
export const project = new Elysia({ prefix: '/api/v1/project' })
.use(projectService)
.get('/', async ({}) => {
try {
return {
success: true,
data: await ProjectService.getAllProjects(),
}
} catch (error) {
return {
success: false,
message: (error as Error).message,
}
}
},{
// This would work
response: t.Object({
success: t.Boolean(),
message: t.Optional(t.String()),
data: t.Optional(t.Any())
}),
})
.get('/test' , async ({}) => {
// This won't show up in the OpenAPI docs
return {
success: true,
message: 'Project route is working!',
}
})// src/index.ts
import { Elysia, t } from 'elysia'
import cors from '@elysiajs/cors'
import { fromTypes, openapi } from '@elysiajs/openapi'
import staticPlugin from '@elysiajs/static'
import { env } from '@yolk-oss/elysia-env'
import { log } from '@/log'
import { device } from '@/modules/device'
import { project } from '@/modules/project'
const app = new Elysia()
.use(cors())
.use(
env({
DATABASE_URL: t.String({
format: 'uri',
description: 'Database connection URL',
}),
}),
)
.use(log.into())
.use(
openapi({
references: fromTypes(
process.env.NODE_ENV === 'production'
? 'dist/index.d.ts'
: 'src/index.ts',
),
documentation: {
info: {
title: 'Elysia TypeGen Example',
version: '1.0.0',
description: 'All response here generated from types',
},
},
}),
)
.use(staticPlugin())
.use(device)
.use(project)
.listen(3000)
log.info(`🦊 ElysiaJS is running at ${app.server?.url}`)
log.info(`⚡️ Check OpenAPI docs at ${app.server?.url}openapi`)The /api/v1/project route displays response type correctly, while /api/v1/project/test doesn't show response type at all.

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels