Use kind guards in registerExamples

This commit is contained in:
Zoe Roux 2024-11-15 23:39:09 +01:00
parent cfe6ce9c7e
commit b0dac24eea
No known key found for this signature in database

View File

@ -1,16 +1,17 @@
import type { TSchema } from "elysia"; import type { TSchema } from "elysia";
import { KindGuard } from "@sinclair/typebox"
export const registerExamples = <T extends TSchema>( export const registerExamples = <T extends TSchema>(
schema: T, schema: T,
...examples: (T["static"] | undefined)[] ...examples: (T["static"] | undefined)[]
) => { ) => {
if ("anyOf" in schema) { if (KindGuard.IsUnion(schema)) {
for (const union of schema.anyOf) { for (const union of schema.anyOf) {
registerExamples(union, ...examples); registerExamples(union, ...examples);
} }
return; return;
} }
if ("allOf" in schema) { if (KindGuard.IsIntersect(schema)) {
for (const intersec of schema.allOf) { for (const intersec of schema.allOf) {
registerExamples(intersec, ...examples); registerExamples(intersec, ...examples);
} }