2025-03-02 17:28:38 +01:00

39 lines
955 B
TypeScript

import { KindGuard } from "@sinclair/typebox";
import type { TSchema } from "elysia";
export const registerExamples = <T extends TSchema>(
schema: T,
...examples: (Partial<T["static"]> | undefined)[]
) => {
if (KindGuard.IsUnion(schema)) {
for (const union of schema.anyOf) {
registerExamples(union, ...examples);
}
return;
}
if (KindGuard.IsIntersect(schema)) {
for (const intersec of schema.allOf) {
registerExamples(intersec, ...examples);
}
return;
}
for (const example of examples) {
if (!example) continue;
for (const [key, val] of Object.entries(example)) {
const prop = schema.properties[
key as keyof typeof schema.properties
] as TSchema;
if (!prop) continue;
prop.examples ??= [];
prop.examples.push(val);
}
}
};
export * from "./bubble";
export * from "./made-in-abyss";
export * from "./dune-1984";
export * from "./dune-2021";
export * from "./dune-collection";
export * from "./others";