@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
17 lines (16 loc) • 617 B
JavaScript
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 });
}