UNPKG

@tsed/schema

Version:
17 lines (16 loc) 617 B
import { isClass } from "@tsed/core"; import { JsonSchema } from "../domain/JsonSchema.js"; import { getJsonEntityStore } from "../utils/getJsonEntityStore.js"; export function from(type = Object) { if (isClass(type)) { const { schema } = getJsonEntityStore(type); schema.properties = function properties(obj) { Object.entries(obj).forEach(([propertyKey, propSchema]) => { getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema); }); return this; }; return schema; } return JsonSchema.from({ type }); }