@@ -139,69 +139,78 @@ export const unwrapSchema = (
139139 // @ts -ignore
140140 const vendor = schema [ '~standard' ] . vendor
141141
142- if ( mapJsonSchema ?. [ vendor ] && typeof mapJsonSchema [ vendor ] === 'function' )
143- return enumToOpenApi ( mapJsonSchema [ vendor ] ( schema ) )
142+ try {
143+ if (
144+ mapJsonSchema ?. [ vendor ] &&
145+ typeof mapJsonSchema [ vendor ] === 'function'
146+ )
147+ return enumToOpenApi ( mapJsonSchema [ vendor ] ( schema ) )
144148
145- switch ( vendor ) {
146- case 'zod' :
147- if ( warned . zod4 || warned . zod3 ) break
149+ switch ( vendor ) {
150+ case 'zod' :
151+ if ( warned . zod4 || warned . zod3 ) break
148152
149- console . warn (
150- "[@elysiajs/openapi] Zod doesn't provide JSON Schema method on the schema"
151- )
153+ console . warn (
154+ "[@elysiajs/openapi] Zod doesn't provide JSON Schema method on the schema"
155+ )
156+
157+ if ( '_zod' in schema ) {
158+ warned . zod4 = true
152159
153- if ( '_zod' in schema ) {
154- warned . zod4 = true
160+ console . warn (
161+ 'For Zod v4, please provide z.toJSONSchema as follows:\n'
162+ )
163+ console . warn ( warnings . zod4 )
164+ } else {
165+ warned . zod3 = true
166+
167+ console . warn (
168+ 'For Zod v3, please install zod-to-json-schema package and use it like this:\n'
169+ )
170+ console . warn ( warnings . zod3 )
171+ }
172+ break
173+
174+ case 'valibot' :
175+ if ( warned . valibot ) break
176+ warned . valibot = true
155177
156178 console . warn (
157- 'For Zod v4, please provide z.toJSONSchema as follows:\n '
179+ '[@elysiajs/openapi] Valibot require a separate package for JSON Schema conversion '
158180 )
159- console . warn ( warnings . zod4 )
160- } else {
161- warned . zod3 = true
162-
163181 console . warn (
164- 'For Zod v3, please install zod- to-json-schema package and use it like this:\n'
182+ 'Please install @valibot/ to-json-schema package and use it like this:\n'
165183 )
166- console . warn ( warnings . zod3 )
167- }
168- break
184+ console . warn ( warnings . valibot )
185+ break
169186
170- case 'valibot' :
171- if ( warned . valibot ) break
172- warned . valibot = true
187+ case 'effect' :
188+ // Effect does not support toJsonSchema method
189+ // Users have to use third party library like effect-zod
190+ if ( warned . effect ) break
191+ warned . effect = true
173192
174- console . warn (
175- '[@elysiajs/openapi] Valibot require a separate package for JSON Schema conversion'
176- )
177- console . warn (
178- 'Please install @valibot/to-json-schema package and use it like this:\n'
179- )
180- console . warn ( warnings . valibot )
181- break
193+ console . warn (
194+ "[@elysiajs/openapi] Effect Schema doesn't provide JSON Schema method on the schema"
195+ )
196+ console . warn (
197+ "please provide JSONSchema from 'effect' package as follows:\n"
198+ )
199+ console . warn ( warnings . effect )
200+ break
201+ }
182202
183- case 'effect' :
184- // Effect does not support toJsonSchema method
185- // Users have to use third party library like effect-zod
186- if ( warned . effect ) break
187- warned . effect = true
203+ if ( vendor === 'arktype' )
204+ // @ts -ignore
205+ return enumToOpenApi ( schema ?. toJsonSchema ?.( ) )
188206
189- console . warn (
190- "[@elysiajs/openapi] Effect Schema doesn't provide JSON Schema method on the schema"
191- )
192- console . warn (
193- "please provide JSONSchema from 'effect' package as follows:\n"
194- )
195- console . warn ( warnings . effect )
196- break
207+ return enumToOpenApi (
208+ // @ts -ignore
209+ schema . toJSONSchema ?.( ) ?? schema ?. toJsonSchema ?.( )
210+ )
211+ } catch ( error ) {
212+ console . warn ( error )
197213 }
198-
199- if ( vendor === 'arktype' )
200- // @ts -ignore
201- return enumToOpenApi ( schema ?. toJsonSchema ?.( ) )
202-
203- // @ts -ignore
204- return enumToOpenApi ( schema . toJSONSchema ?.( ) ?? schema ?. toJsonSchema ?.( ) )
205214}
206215
207216export const enumToOpenApi = <
0 commit comments