UNPKG

@tsed/common

Version:
107 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Enum = void 0; const schema_1 = require("@tsed/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. */ function Enum(enumValue, ...enumValues) { return schema_1.Enum(enumValue, ...enumValues); } exports.Enum = Enum; //# sourceMappingURL=enum.js.map