@tsed/schema 8.19.1 → 8.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/lib/esm/constants/OperationVerbs.js +35 -0
  2. package/lib/esm/constants/VendorKeys.js +29 -0
  3. package/lib/esm/constants/httpStatusMessages.js +59 -0
  4. package/lib/esm/constants/jsonSchemaProperties.js +55 -0
  5. package/lib/esm/decorators/class/children.js +93 -5
  6. package/lib/esm/decorators/class/discriminatorValue.js +124 -20
  7. package/lib/esm/decorators/collections/collectionContains.js +91 -10
  8. package/lib/esm/decorators/collections/maxItems.js +97 -27
  9. package/lib/esm/decorators/collections/maxProperties.js +96 -30
  10. package/lib/esm/decorators/collections/minItems.js +122 -27
  11. package/lib/esm/decorators/collections/minProperties.js +132 -31
  12. package/lib/esm/decorators/common/additionalProperties.js +59 -4
  13. package/lib/esm/decorators/common/allOf.js +61 -6
  14. package/lib/esm/decorators/common/allow.js +56 -12
  15. package/lib/esm/decorators/common/any.js +58 -18
  16. package/lib/esm/decorators/common/anyOf.js +65 -9
  17. package/lib/esm/decorators/common/const.js +72 -30
  18. package/lib/esm/decorators/common/customKey.js +132 -12
  19. package/lib/esm/decorators/common/default.js +85 -19
  20. package/lib/esm/decorators/common/discriminatorKey.js +123 -0
  21. package/lib/esm/decorators/common/errorMsg.js +48 -2
  22. package/lib/esm/decorators/common/example.js +68 -6
  23. package/lib/esm/decorators/common/examples.js +99 -6
  24. package/lib/esm/decorators/common/format.js +86 -52
  25. package/lib/esm/decorators/common/nullable.js +77 -11
  26. package/lib/esm/decorators/common/oneOf.js +93 -9
  27. package/lib/esm/decorators/common/optional.js +93 -4
  28. package/lib/esm/decorators/common/property.js +42 -6
  29. package/lib/esm/decorators/common/readOnly.js +106 -5
  30. package/lib/esm/decorators/common/required.js +57 -20
  31. package/lib/esm/decorators/common/writeOnly.js +117 -5
  32. package/lib/esm/domain/JsonClassStore.js +75 -0
  33. package/lib/esm/domain/JsonDiscriminator.js +57 -0
  34. package/lib/esm/domain/JsonEntityStore.js +46 -0
  35. package/lib/esm/domain/JsonFormatTypes.js +39 -0
  36. package/lib/esm/domain/JsonLazyRef.js +33 -0
  37. package/lib/esm/domain/JsonMap.js +32 -0
  38. package/lib/esm/domain/JsonMedia.js +28 -0
  39. package/lib/esm/domain/JsonMethodStore.js +56 -0
  40. package/lib/esm/domain/JsonOperation.js +43 -0
  41. package/lib/esm/domain/JsonOperationPathsMap.js +38 -0
  42. package/lib/esm/domain/JsonOperationRoute.js +54 -0
  43. package/lib/esm/domain/JsonParameter.js +35 -0
  44. package/lib/esm/domain/JsonParameterStore.js +71 -0
  45. package/lib/esm/domain/JsonParameterTypes.js +26 -0
  46. package/lib/esm/domain/JsonPropertyStore.js +44 -0
  47. package/lib/esm/domain/JsonRequestBody.js +26 -0
  48. package/lib/esm/domain/JsonResponse.js +29 -0
  49. package/lib/esm/domain/JsonSchema.js +365 -16
  50. package/lib/esm/domain/SpecTypes.js +26 -0
  51. package/lib/esm/fn/boolean.js +39 -3
  52. package/lib/esm/fn/number.js +45 -3
  53. package/lib/esm/fn/string.js +43 -3
  54. package/lib/types/constants/OperationVerbs.d.ts +35 -0
  55. package/lib/types/constants/VendorKeys.d.ts +29 -0
  56. package/lib/types/constants/httpStatusMessages.d.ts +59 -0
  57. package/lib/types/constants/jsonSchemaProperties.d.ts +55 -0
  58. package/lib/types/decorators/class/children.d.ts +93 -5
  59. package/lib/types/decorators/class/discriminatorValue.d.ts +124 -20
  60. package/lib/types/decorators/collections/collectionContains.d.ts +91 -10
  61. package/lib/types/decorators/collections/maxItems.d.ts +97 -27
  62. package/lib/types/decorators/collections/maxProperties.d.ts +96 -30
  63. package/lib/types/decorators/collections/minItems.d.ts +122 -27
  64. package/lib/types/decorators/collections/minProperties.d.ts +132 -31
  65. package/lib/types/decorators/common/additionalProperties.d.ts +59 -4
  66. package/lib/types/decorators/common/allOf.d.ts +61 -6
  67. package/lib/types/decorators/common/allow.d.ts +56 -12
  68. package/lib/types/decorators/common/any.d.ts +58 -18
  69. package/lib/types/decorators/common/anyOf.d.ts +65 -9
  70. package/lib/types/decorators/common/const.d.ts +72 -30
  71. package/lib/types/decorators/common/customKey.d.ts +132 -12
  72. package/lib/types/decorators/common/default.d.ts +85 -19
  73. package/lib/types/decorators/common/discriminatorKey.d.ts +123 -0
  74. package/lib/types/decorators/common/errorMsg.d.ts +48 -2
  75. package/lib/types/decorators/common/example.d.ts +68 -6
  76. package/lib/types/decorators/common/examples.d.ts +99 -6
  77. package/lib/types/decorators/common/format.d.ts +86 -52
  78. package/lib/types/decorators/common/nullable.d.ts +77 -11
  79. package/lib/types/decorators/common/oneOf.d.ts +93 -9
  80. package/lib/types/decorators/common/optional.d.ts +93 -4
  81. package/lib/types/decorators/common/property.d.ts +42 -6
  82. package/lib/types/decorators/common/readOnly.d.ts +106 -5
  83. package/lib/types/decorators/common/required.d.ts +57 -20
  84. package/lib/types/decorators/common/writeOnly.d.ts +117 -5
  85. package/lib/types/domain/JsonClassStore.d.ts +75 -0
  86. package/lib/types/domain/JsonDiscriminator.d.ts +57 -0
  87. package/lib/types/domain/JsonEntityStore.d.ts +51 -0
  88. package/lib/types/domain/JsonFormatTypes.d.ts +39 -0
  89. package/lib/types/domain/JsonLazyRef.d.ts +33 -0
  90. package/lib/types/domain/JsonMap.d.ts +32 -0
  91. package/lib/types/domain/JsonMedia.d.ts +28 -0
  92. package/lib/types/domain/JsonMethodStore.d.ts +66 -0
  93. package/lib/types/domain/JsonOperation.d.ts +51 -0
  94. package/lib/types/domain/JsonOperationPathsMap.d.ts +38 -0
  95. package/lib/types/domain/JsonOperationRoute.d.ts +54 -0
  96. package/lib/types/domain/JsonParameter.d.ts +35 -0
  97. package/lib/types/domain/JsonParameterStore.d.ts +97 -0
  98. package/lib/types/domain/JsonParameterTypes.d.ts +26 -0
  99. package/lib/types/domain/JsonPropertyStore.d.ts +44 -0
  100. package/lib/types/domain/JsonRequestBody.d.ts +31 -0
  101. package/lib/types/domain/JsonResponse.d.ts +34 -0
  102. package/lib/types/domain/JsonSchema.d.ts +422 -19
  103. package/lib/types/domain/SpecTypes.d.ts +26 -0
  104. package/lib/types/domain/types.d.ts +90 -0
  105. package/lib/types/fn/boolean.d.ts +39 -3
  106. package/lib/types/fn/number.d.ts +45 -3
  107. package/lib/types/fn/string.d.ts +43 -3
  108. package/lib/types/interfaces/IgnoreCallback.d.ts +24 -0
  109. package/lib/types/interfaces/JsonHookContext.d.ts +31 -0
  110. package/lib/types/interfaces/JsonOpenSpec.d.ts +33 -0
  111. package/lib/types/interfaces/JsonSchemaOptions.d.ts +26 -0
  112. package/package.json +7 -7
@@ -1,10 +1,50 @@
1
1
  import { from } from "./from.js";
2
2
  /**
3
- * Declare a new string model.
3
+ * Create a string schema programmatically.
4
4
  *
5
- * See @@JsonSchema@@ to discover available methods.
5
+ * This function provides a fluent API for building string schemas without decorators.
6
+ * It returns a JsonSchema instance configured for string type, which can be further
7
+ * customized with validation constraints, formats, and other JSON Schema properties.
6
8
  *
7
- * @schemaFunctional
9
+ * ### Usage
10
+ *
11
+ * ```typescript
12
+ * import {string} from "@tsed/schema";
13
+ *
14
+ * // Basic string schema
15
+ * const nameSchema = string();
16
+ *
17
+ * // String with constraints
18
+ * const emailSchema = string()
19
+ * .format("email")
20
+ * .minLength(5)
21
+ * .maxLength(100)
22
+ * .description("User email address");
23
+ *
24
+ * // String with pattern
25
+ * const phoneSchema = string()
26
+ * .pattern(/^\d{3}-\d{3}-\d{4}$/)
27
+ * .description("Phone number in format: 123-456-7890");
28
+ *
29
+ * // Enum string
30
+ * const statusSchema = string()
31
+ * .enum("active", "inactive", "pending");
32
+ * ```
33
+ *
34
+ * ### Available Methods
35
+ *
36
+ * The returned JsonSchema provides many chainable methods:
37
+ * - `minLength(n)` / `maxLength(n)` - Length constraints
38
+ * - `pattern(regex)` - Pattern matching
39
+ * - `format(type)` - Format validation (email, uri, date-time, etc.)
40
+ * - `enum(...values)` - Restrict to specific values
41
+ * - `description(text)` - Add description
42
+ * - `default(value)` - Set default value
43
+ * - `nullable()` - Allow null values
44
+ *
45
+ * @returns A new JsonSchema configured as a string type
46
+ *
47
+ * @public
8
48
  */
9
49
  export function string() {
10
50
  return from(String);
@@ -1,3 +1,23 @@
1
+ /**
2
+ * HTTP and WebSocket operation verbs supported by Ts.ED.
3
+ *
4
+ * This enum defines all supported operation verbs for HTTP endpoints,
5
+ * WebSocket operations, and special routing cases. These verbs are used
6
+ * to define route handlers and generate OpenAPI specifications.
7
+ *
8
+ * ### HTTP Verbs
9
+ * Standard HTTP methods (GET, POST, PUT, PATCH, DELETE, etc.) are supported
10
+ * for RESTful API operations.
11
+ *
12
+ * ### WebSocket Verbs
13
+ * PUBLISH and SUBSCRIBE are used for WebSocket operations and message patterns.
14
+ *
15
+ * ### Special Verbs
16
+ * - ALL: Matches all HTTP methods for a route
17
+ * - CUSTOM: Allows custom HTTP methods
18
+ *
19
+ * @public
20
+ */
1
21
  export declare enum OperationVerbs {
2
22
  ALL = "ALL",// special key
3
23
  GET = "GET",
@@ -12,5 +32,20 @@ export declare enum OperationVerbs {
12
32
  SUBSCRIBE = "SUBSCRIBE",
13
33
  CUSTOM = "CUSTOM"
14
34
  }
35
+ /**
36
+ * List of HTTP operation verbs including the special ALL and CUSTOM verbs.
37
+ *
38
+ * This array contains all HTTP methods supported for REST API operations,
39
+ * excluding WebSocket-specific verbs (PUBLISH, SUBSCRIBE).
40
+ *
41
+ * @public
42
+ */
15
43
  export declare const OPERATION_HTTP_VERBS: OperationVerbs[];
44
+ /**
45
+ * List of WebSocket operation verbs for pub/sub messaging patterns.
46
+ *
47
+ * These verbs are used to define WebSocket message handlers in Ts.ED applications.
48
+ *
49
+ * @public
50
+ */
16
51
  export declare const OPERATION_WS_VERBS: OperationVerbs[];
@@ -1,3 +1,32 @@
1
+ /**
2
+ * Vendor extension keys used in JSON schemas and OpenAPI specifications.
3
+ *
4
+ * These keys are used as custom extension properties (prefixed with `x-` in OpenAPI)
5
+ * to store Ts.ED-specific metadata in generated schemas. Vendor extensions enable
6
+ * advanced features like generic type handling, group-based serialization, and
7
+ * nullable type support.
8
+ *
9
+ * ### Usage
10
+ *
11
+ * Vendor keys are automatically added to schemas by decorators and mappers.
12
+ * They preserve TypeScript type information and enable runtime schema transformations.
13
+ *
14
+ * ### Generic Type Keys
15
+ * - GENERIC_LABELS: Labels for generic type parameters
16
+ * - GENERIC_LABEL: Single generic type label
17
+ * - GENERIC_OF: Generic type reference
18
+ *
19
+ * ### Group Keys
20
+ * - GROUPS: Property group memberships
21
+ * - GROUPS_NAME: Named group identifier
22
+ * - FORWARD_GROUPS: Groups forwarded to nested properties
23
+ * - ALLOWED_GROUPS: Groups allowed for access
24
+ *
25
+ * ### Type Keys
26
+ * - NULLABLE: Marks a type as nullable
27
+ *
28
+ * @public
29
+ */
1
30
  export declare enum VendorKeys {
2
31
  GENERIC_LABELS = "genericLabels",
3
32
  GENERIC_LABEL = "genericLabel",
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Map of HTTP status codes to their human-readable labels and constant names.
3
+ *
4
+ * This constant provides a standardized lookup table for all HTTP status codes,
5
+ * mapping each code to both a descriptive label and a constant-case identifier.
6
+ * The mapping is generated from the standard HTTP status code definitions.
7
+ *
8
+ * ### Structure
9
+ *
10
+ * Each entry contains:
11
+ * - `label`: Human-readable status message (e.g., "Not Found")
12
+ * - `code`: Constant-case identifier (e.g., "NOT_FOUND")
13
+ *
14
+ * ### Usage
15
+ *
16
+ * ```typescript
17
+ * // Access status information
18
+ * const status404 = HTTP_STATUS_MESSAGES["404"];
19
+ * // { label: "Not Found", code: "NOT_FOUND" }
20
+ * ```
21
+ *
22
+ * @public
23
+ */
1
24
  export declare const HTTP_STATUS_MESSAGES: {
2
25
  [x: string]: {
3
26
  label: string;
@@ -7,5 +30,41 @@ export declare const HTTP_STATUS_MESSAGES: {
7
30
  code: string;
8
31
  };
9
32
  };
33
+ /**
34
+ * Get the constant-case identifier for an HTTP status code.
35
+ *
36
+ * Converts a status code to its constant representation (e.g., 404 → "NOT_FOUND").
37
+ * Useful for generating TypeScript constants and error codes.
38
+ *
39
+ * ### Usage
40
+ *
41
+ * ```typescript
42
+ * const constant = getStatusConstant(404);
43
+ * // Returns: "NOT_FOUND"
44
+ * ```
45
+ *
46
+ * @param status - The HTTP status code (number or string)
47
+ * @returns The constant-case identifier, or undefined if not found
48
+ *
49
+ * @public
50
+ */
10
51
  export declare function getStatusConstant(status: number | string): any;
52
+ /**
53
+ * Get the human-readable message for an HTTP status code.
54
+ *
55
+ * Returns the descriptive label associated with a status code
56
+ * (e.g., 404 → "Not Found").
57
+ *
58
+ * ### Usage
59
+ *
60
+ * ```typescript
61
+ * const message = getStatusMessage(404);
62
+ * // Returns: "Not Found"
63
+ * ```
64
+ *
65
+ * @param status - The HTTP status code (number or string)
66
+ * @returns The human-readable status message, or undefined if not found
67
+ *
68
+ * @public
69
+ */
11
70
  export declare function getStatusMessage(status: number | string): any;
@@ -1,7 +1,62 @@
1
+ /**
2
+ * JSON Schema properties for composition keywords (oneOf, allOf, anyOf).
3
+ *
4
+ * These properties define schema composition, allowing multiple schemas to be
5
+ * combined using different logical operators.
6
+ *
7
+ * @public
8
+ */
1
9
  export declare const MANY_OF_PROPERTIES: string[];
10
+ /**
11
+ * JSON Schema properties specific to string type validation.
12
+ *
13
+ * These properties control string length constraints, pattern matching,
14
+ * and format validation (e.g., email, uri, date-time).
15
+ *
16
+ * @public
17
+ */
2
18
  export declare const STRING_PROPERTIES: string[];
19
+ /**
20
+ * JSON Schema properties specific to boolean type validation.
21
+ *
22
+ * Currently empty as boolean types have no specific validation properties
23
+ * beyond the type itself.
24
+ *
25
+ * @public
26
+ */
3
27
  export declare const BOOLEAN_PROPERTIES: never[];
28
+ /**
29
+ * JSON Schema properties specific to number and integer type validation.
30
+ *
31
+ * These properties control numeric range constraints and divisibility rules.
32
+ *
33
+ * @public
34
+ */
4
35
  export declare const NUMBER_PROPERTIES: string[];
36
+ /**
37
+ * JSON Schema properties specific to array type validation.
38
+ *
39
+ * These properties control array size constraints, uniqueness requirements,
40
+ * item schemas, and containment rules.
41
+ *
42
+ * @public
43
+ */
5
44
  export declare const ARRAY_PROPERTIES: string[];
45
+ /**
46
+ * JSON Schema properties specific to object type validation.
47
+ *
48
+ * These properties control object property constraints, pattern-based properties,
49
+ * and property dependencies.
50
+ *
51
+ * @public
52
+ */
6
53
  export declare const OBJECT_PROPERTIES: string[];
54
+ /**
55
+ * JSON Schema properties common to all types.
56
+ *
57
+ * These properties can be applied to any schema regardless of its type,
58
+ * defining constant values or enumerated options.
59
+ *
60
+ * @public
61
+ */
7
62
  export declare const COMMON_PROPERTIES: string[];
@@ -1,11 +1,99 @@
1
1
  import { Type } from "@tsed/core";
2
2
  /**
3
- * Add Children class to compose routes
3
+ * Declares child controller classes for route composition and hierarchy.
4
+ *
5
+ * The `@Children()` decorator establishes parent-child relationships between controllers,
6
+ * allowing you to compose complex routing hierarchies and organize related endpoints into
7
+ * logical groups. Child controllers inherit the parent's base path.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * @Controller("/users")
13
+ * @Children(UserProfileController, UserSettingsController)
14
+ * class UserController {
15
+ * @Get("/")
16
+ * list() {
17
+ * // GET /users/
18
+ * }
19
+ * }
20
+ *
21
+ * @Controller("/profile")
22
+ * class UserProfileController {
23
+ * @Get("/")
24
+ * getProfile() {
25
+ * // GET /users/profile/
26
+ * }
27
+ * }
28
+ *
29
+ * @Controller("/settings")
30
+ * class UserSettingsController {
31
+ * @Get("/")
32
+ * getSettings() {
33
+ * // GET /users/settings/
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * ### Multi-Level Hierarchy
39
+ *
40
+ * ```typescript
41
+ * @Controller("/api")
42
+ * @Children(UsersController, ProductsController)
43
+ * class ApiController {}
44
+ *
45
+ * @Controller("/users")
46
+ * @Children(UserProfileController, UserOrdersController)
47
+ * class UsersController {}
48
+ *
49
+ * @Controller("/profile")
50
+ * class UserProfileController {
51
+ * @Get("/")
52
+ * get() {
53
+ * // GET /api/users/profile/
54
+ * }
55
+ * }
56
+ * ```
57
+ *
58
+ * ### Resource Organization
59
+ *
60
+ * ```typescript
61
+ * @Controller("/admin")
62
+ * @Children(
63
+ * AdminUsersController,
64
+ * AdminProductsController,
65
+ * AdminReportsController
66
+ * )
67
+ * class AdminController {
68
+ * // Parent controller for all admin routes
69
+ * }
70
+ * ```
71
+ *
72
+ * ### Use Cases
73
+ *
74
+ * - **Route Organization**: Group related endpoints logically
75
+ * - **API Versioning**: Organize versions with child controllers
76
+ * - **Module Structure**: Mirror application module hierarchy in routes
77
+ * - **Access Control**: Apply middleware at parent level for all children
78
+ * - **Documentation**: Generate organized OpenAPI specs with grouped endpoints
79
+ *
80
+ * ### Benefits
81
+ *
82
+ * - **Maintainability**: Keep related routes together
83
+ * - **Scalability**: Easy to add new endpoint groups
84
+ * - **Clarity**: Clear route hierarchy in codebase
85
+ * - **Reusability**: Share middleware and configuration across children
86
+ *
87
+ * ### Important Notes
88
+ *
89
+ * - Children automatically inherit parent's base path
90
+ * - Parent-child relationship is stored in metadata
91
+ * - Useful for generating structured API documentation
92
+ * - Middleware on parent applies to all children
93
+ *
94
+ * @param children - Controller classes to register as children
4
95
  *
5
96
  * @decorator
6
- * @swagger
7
- * @schema
8
- * @classDecorator
9
- * @param children
97
+ * @public
10
98
  */
11
99
  export declare function Children(...children: Type<any>[]): ClassDecorator;
@@ -1,42 +1,146 @@
1
1
  /**
2
- * Declare a Discriminator value on a child class.
2
+ * Declares the discriminator value for a subclass in a polymorphic hierarchy.
3
3
  *
4
- * ```ts
5
- * export class Event {
6
- * @DiscriminatorKey() // declare this property a discriminator key
4
+ * The `@DiscriminatorValue()` decorator specifies the value that should be present in the
5
+ * discriminator key property to identify this specific subclass. This is used together with
6
+ * `@DiscriminatorKey()` on the base class for proper polymorphic type resolution during
7
+ * serialization and deserialization.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * abstract class Event {
13
+ * @DiscriminatorKey()
7
14
  * type: string;
8
15
  *
9
16
  * @Property()
10
- * value: string;
17
+ * timestamp: Date;
11
18
  * }
12
19
  *
13
20
  * @DiscriminatorValue("page_view")
14
- * export class PageView extends Event {
15
- * @Required()
21
+ * class PageView extends Event {
22
+ * @Property()
16
23
  * url: string;
24
+ *
25
+ * @Property()
26
+ * referrer: string;
17
27
  * }
18
28
  *
19
29
  * @DiscriminatorValue("action")
20
- * export class Action extends Event {
21
- * @Required()
22
- * event: string;
30
+ * class Action extends Event {
31
+ * @Property()
32
+ * actionName: string;
33
+ *
34
+ * @Property()
35
+ * metadata: object;
23
36
  * }
37
+ * ```
24
38
  *
25
- * @DiscriminatorValue()
26
- * export class CustomAction extends Event {
27
- * @Required()
28
- * event: string;
39
+ * ### Auto-Generated Values
29
40
  *
41
+ * If no value is provided, it auto-generates from the class name in snake_case:
42
+ *
43
+ * ```typescript
44
+ * @DiscriminatorValue() // Generates "custom_action"
45
+ * class CustomAction extends Event {
30
46
  * @Property()
31
- * meta: string;
47
+ * customField: string;
32
48
  * }
33
49
  * ```
34
50
  *
51
+ * ### Multiple Values (Aliases)
52
+ *
53
+ * Support multiple discriminator values for the same class:
54
+ *
55
+ * ```typescript
56
+ * @DiscriminatorValue("click", "tap", "press")
57
+ * class ClickEvent extends Event {
58
+ * // Matches when type is "click", "tap", OR "press"
59
+ * }
60
+ * ```
61
+ *
62
+ * ### Payment Methods Example
63
+ *
64
+ * ```typescript
65
+ * abstract class PaymentMethod {
66
+ * @DiscriminatorKey()
67
+ * type: string;
68
+ * }
69
+ *
70
+ * @DiscriminatorValue("credit_card")
71
+ * class CreditCardPayment extends PaymentMethod {
72
+ * @Property()
73
+ * cardNumber: string;
74
+ *
75
+ * @Property()
76
+ * cvv: string;
77
+ * }
78
+ *
79
+ * @DiscriminatorValue("paypal")
80
+ * class PayPalPayment extends PaymentMethod {
81
+ * @Property()
82
+ * email: string;
83
+ * }
84
+ *
85
+ * @DiscriminatorValue("bank_transfer")
86
+ * class BankTransfer extends PaymentMethod {
87
+ * @Property()
88
+ * iban: string;
89
+ * }
90
+ * ```
91
+ *
92
+ * ### With API Endpoints
93
+ *
94
+ * ```typescript
95
+ * @Post("/events")
96
+ * async trackEvent(@BodyParams() event: Event) {
97
+ * // Framework automatically deserializes to correct subclass
98
+ * // based on the 'type' field value in request body
99
+ * if (event instanceof PageView) {
100
+ * // Handle page view
101
+ * } else if (event instanceof Action) {
102
+ * // Handle action
103
+ * }
104
+ * }
105
+ * ```
106
+ *
107
+ * ### OpenAPI Generation
108
+ *
109
+ * Generates proper discriminator mapping:
110
+ *
111
+ * ```json
112
+ * {
113
+ * "discriminator": {
114
+ * "propertyName": "type",
115
+ * "mapping": {
116
+ * "page_view": "#/components/schemas/PageView",
117
+ * "action": "#/components/schemas/Action"
118
+ * }
119
+ * }
120
+ * }
121
+ * ```
122
+ *
123
+ * ### Use Cases
124
+ *
125
+ * - **Event Systems**: Different event types with shared structure
126
+ * - **Payment Processing**: Multiple payment method types
127
+ * - **Notification Systems**: Various notification channels
128
+ * - **Content Types**: Polymorphic content (articles, videos, images)
129
+ * - **API Responses**: Different response formats based on type
130
+ *
131
+ * ### Important Notes
132
+ *
133
+ * - Must be used on subclasses that extend a class with `@DiscriminatorKey()`
134
+ * - Each subclass should have a unique discriminator value
135
+ * - If omitted, value is auto-generated from class name (snake_case)
136
+ * - Multiple values create aliases for backward compatibility
137
+ * - Works with OpenAPI discriminator specification
138
+ *
139
+ * @param value - The discriminator value (auto-generated if omitted)
140
+ * @param values - Additional alias values for this subclass
141
+ *
35
142
  * @decorator
36
- * @swagger
37
- * @schema
38
- * @classDecorator
39
- * @param value
40
- * @param values
143
+ * @public
144
+ * @see DiscriminatorKey
41
145
  */
42
146
  export declare function DiscriminatorValue(value?: string, ...values: string[]): ClassDecorator;
@@ -1,21 +1,102 @@
1
1
  /**
2
- * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...
2
+ * Validates that an array contains at least one element matching the specified type/schema.
3
3
  *
4
- * The array instance will be valid against "contains" if at least one of its elements is valid against the given schema.
4
+ * The `@CollectionContains()` decorator uses JSON Schema's `contains` keyword to ensure
5
+ * that at least one item in the array is valid against the given schema. This is useful
6
+ * for validation where you need to guarantee certain elements exist in a collection
7
+ * without requiring all elements to match.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * class SearchResults {
13
+ * @CollectionContains(String)
14
+ * tags: string[];
15
+ * // Array must contain at least one string
16
+ * }
17
+ * ```
18
+ *
19
+ * ### With String Constraints
20
+ *
21
+ * ```typescript
22
+ * class ValidationModel {
23
+ * @CollectionContains(String).MinLength(5).MaxLength(20)
24
+ * keywords: string[];
25
+ * // Must contain at least one string between 5-20 characters
26
+ * }
27
+ * ```
28
+ *
29
+ * ### With Custom Classes
5
30
  *
6
31
  * ```typescript
7
- * class Model {
8
- * @CollectionContains(String).MinLength(0).MaxLength(0)
9
- * property: string[];
32
+ * class AdminUser {
33
+ * @Property()
34
+ * role: string;
35
+ *
36
+ * @Property()
37
+ * permissions: string[];
38
+ * }
39
+ *
40
+ * class Team {
41
+ * @CollectionContains(AdminUser)
42
+ * members: User[];
43
+ * // Team must contain at least one AdminUser
10
44
  * }
11
45
  * ```
12
46
  *
13
- * @param {Type<any>} type
47
+ * ### Mixed Type Arrays
48
+ *
49
+ * ```typescript
50
+ * class DataSet {
51
+ * @CollectionContains(Number).Minimum(100)
52
+ * values: (number | string)[];
53
+ * // Must contain at least one number >= 100
54
+ * }
55
+ * ```
56
+ *
57
+ * ### Validation Behavior
58
+ *
59
+ * ```typescript
60
+ * @CollectionContains(String).MinLength(3)
61
+ * items: string[];
62
+ *
63
+ * // Valid:
64
+ * ["a", "abc", "b"] // Contains "abc" with length >= 3
65
+ * ["hello", "world"] // Both match, but only one needed
66
+ *
67
+ * // Invalid:
68
+ * ["a", "b", "c"] // No string with length >= 3
69
+ * [] // Empty array has no matching elements
70
+ * ```
71
+ *
72
+ * ### Use Cases
73
+ *
74
+ * - **Required Elements**: Ensure specific items exist in collections
75
+ * - **Mixed Arrays**: Validate presence of certain types in heterogeneous arrays
76
+ * - **Quality Checks**: Guarantee minimum quality standards for at least one item
77
+ * - **Search Results**: Ensure relevant results exist in search responses
78
+ *
79
+ * ### Chaining with Other Validators
80
+ *
81
+ * ```typescript
82
+ * class ProductList {
83
+ * @CollectionContains(String).MinLength(3)
84
+ * @MinItems(1)
85
+ * @MaxItems(10)
86
+ * names: string[];
87
+ * // 1-10 items, with at least one name having 3+ characters
88
+ * }
89
+ * ```
90
+ *
91
+ * ### vs CollectionOf
92
+ *
93
+ * - `@CollectionContains()`: At least **one** element must match the schema
94
+ * - `@CollectionOf()`: **All** elements must match the schema
95
+ *
96
+ * @param type - The type or class that at least one array element must match
97
+ *
14
98
  * @decorator
15
99
  * @validation
16
- * @swagger
17
- * @schema
18
- * @input
19
- * @collections
100
+ * @public
20
101
  */
21
102
  export declare function CollectionContains(type: any): import("./collectionOf.js").CollectionOfChainedDecorators;