работаем бля работаем
This commit is contained in:
12
server/utils/typebox-ref.ts
Normal file
12
server/utils/typebox-ref.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Static, TSchema, TSchemaOptions, TUnsafe } from 'typebox'
|
||||
import { Unsafe } from 'typebox'
|
||||
|
||||
export function TypeboxRef<T extends TSchema>(t: T, options: TSchemaOptions = {}): TUnsafe<Static<T>> {
|
||||
const id = (t as unknown as Record<string, string | undefined>).$id
|
||||
|
||||
if (!id) {
|
||||
throw new Error('missing ID on schema')
|
||||
}
|
||||
|
||||
return Unsafe<Static<T>>({ ...t, $ref: id, $id: undefined, ...options })
|
||||
}
|
||||
Reference in New Issue
Block a user