UNPKG

@tsed/common

Version:
101 lines (100 loc) 1.92 kB
import { JSONSchema6Type } from "json-schema"; /** * The enum keyword is used to restrict a value to a fixed set of values. * It must be an array with at least one element, where each element is unique. * * Elements in the array might be of any value, including null. * * ::: warning * This decorator will be removed in v7. * For v6 user, use @@Enum@@ from @tsed/schema instead of @tsed/common. * ::: * * ## Example * ### With primitive type * * ```typescript * class Model { * @Enum("value1", "value2") * property: "value1" | "value2"; * } * ``` * * Will produce: * * ```json * { * "type": "object", * "properties": { * "property": { * "type": "string", * "enum": ["value1", "value2"] * } * } * } * ``` * * ### With array type * * ```typescript * class Model { * @Enum("value1", "value2") * property: ("value1" | "value2")[]; * } * ``` * * Will produce: * * ```json * { * "type": "object", * "properties": { * "property": { * "type": "array", * "items": { * "type": "string", * "enum": ["value1", "value2"] * } * } * } * } * ``` * * ### With Typescript Enum * * ```typescript * enum SomeEnum { * ENUM_1 = "enum1", * ENUM_2 = "enum2" * } * * class Model { * @Enum(SomeEnum) * property: SomeEnum; * } * ``` * * Will produce: * * ```json * { * "type": "object", * "properties": { * "property": { * "type": "string", * "enum": ["enum1", "enum2"] * } * } * } * ``` * * @param {string | number | boolean | {}} enumValue * @param enumValues * @decorator * @validation * @swagger * @schema * @ignore * @deprecated Since v6. Use @Enum decorator from @tsed/schema instead of. */ export declare function Enum(enumValue: JSONSchema6Type | any, ...enumValues: JSONSchema6Type[]): (...args: any[]) => any;