File tree Expand file tree Collapse file tree 4 files changed +36
-9
lines changed Expand file tree Collapse file tree 4 files changed +36
-9
lines changed Original file line number Diff line number Diff line change 1+ # 1.4.6 - 21 Sep 2025
2+ Bug fix:
3+ - type gen: handle inline 200 response schema assignment
4+
15# 1.4.5 - 20 Sep 2025
26Improvement:
37- reference model now handle content type correctly
Original file line number Diff line number Diff line change 11import { Elysia , t } from 'elysia'
22import { openapi , withHeaders } from '../src/index'
33import { fromTypes } from '../src/gen'
4+ import z from 'zod'
45
5- export const app = new Elysia ( { prefix : '/id' } )
6+ export const app = new Elysia ( )
67 . use (
78 openapi ( {
9+ mapJsonSchema : {
10+ zod : z . toJSONSchema
11+ } ,
812 references : fromTypes ( 'example/gen.ts' , {
913 debug : true
1014 } )
@@ -49,13 +53,13 @@ export const app = new Elysia({ prefix: '/id' })
4953 . post (
5054 '/character' ,
5155 ( ) => ( {
52- name : 'Elysia'
56+ name : 'Lilith' as const
5357 } ) ,
5458 {
5559 body : 'character.name' ,
56- response : {
57- 200 : 'character.thing'
58- }
60+ response : z . object ( {
61+ name : z . literal ( 'Lilith' )
62+ } )
5963 }
6064 )
6165 . listen ( 3000 )
Original file line number Diff line number Diff line change 11{
22 "name" : " @elysiajs/openapi" ,
3- "version" : " 1.4.5 " ,
3+ "version" : " 1.4.6 " ,
44 "description" : " Plugin for Elysia to auto-generate API documentation" ,
55 "author" : {
66 "name" : " saltyAom" ,
Original file line number Diff line number Diff line change @@ -290,14 +290,31 @@ export function toOpenAPISchema(
290290 ) )
291291 if ( isValidSchema ( schema ) ) {
292292 if ( ! hooks . response ) hooks . response = { }
293+ else if (
294+ typeof hooks . response !== 'object' ||
295+ ( hooks . response as TSchema ) . type ||
296+ ( hooks . response as TSchema ) . $ref ||
297+ ( hooks . response as any ) [ '~standard' ]
298+ )
299+ // @ts -ignore
300+ hooks . response = {
301+ 200 : hooks . response as any
302+ }
293303
294304 if (
295305 ! hooks . response [
296306 status as keyof ( typeof hooks ) [ 'response' ]
297307 ]
298308 )
299- // @ts -ignore
300- hooks . response [ status ] = schema
309+ try {
310+ // @ts -ignore
311+ hooks . response [ status ] = schema
312+ } catch ( error ) {
313+ console . log (
314+ '[@elysiajs/openapi/gen] Failed to assigned response schema'
315+ )
316+ console . log ( error )
317+ }
301318 }
302319 }
303320
@@ -496,8 +513,10 @@ export function toOpenAPISchema(
496513
497514 if (
498515 typeof hooks . response === 'object' &&
516+ // TypeBox
499517 ! ( hooks . response as TSchema ) . type &&
500- ! ( hooks . response as TSchema ) . $ref
518+ ! ( hooks . response as TSchema ) . $ref &&
519+ ! ( hooks . response as any ) [ '~standard' ]
501520 ) {
502521 for ( let [ status , schema ] of Object . entries ( hooks . response ) ) {
503522 const response = unwrapSchema ( schema , vendors )
You can’t perform that action at this time.
0 commit comments