@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
30 lines (29 loc) • 615 B
JavaScript
import { useDecorators } from "@tsed/core";
import { Any } from "./any.js";
import { Property } from "./property.js";
/**
* Set field as nullable.
*
* ## Example
*
* ```typescript
* class Model {
* @Nullable(Date)
* property: Date | null;
*
* @Nullable(String, Number, Boolean)
* property: string | number | boolean | null;
* }
* ```
*
* @returns {Function}
* @decorator
* @validation
* @swagger
* @schema
* @input
*/
export function Nullable(type, ...types) {
types = [type, ...types];
return useDecorators(types.length === 1 && Property(types[0]), Any(null, ...types));
}