@tsed/schema 8.19.2 → 8.19.4

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 (113) hide show
  1. package/lib/esm/components/open-spec/nullableMapper.js +6 -2
  2. package/lib/esm/constants/OperationVerbs.js +35 -0
  3. package/lib/esm/constants/VendorKeys.js +29 -0
  4. package/lib/esm/constants/httpStatusMessages.js +59 -0
  5. package/lib/esm/constants/jsonSchemaProperties.js +55 -0
  6. package/lib/esm/decorators/class/children.js +93 -5
  7. package/lib/esm/decorators/class/discriminatorValue.js +124 -20
  8. package/lib/esm/decorators/collections/collectionContains.js +91 -10
  9. package/lib/esm/decorators/collections/maxItems.js +97 -27
  10. package/lib/esm/decorators/collections/maxProperties.js +96 -30
  11. package/lib/esm/decorators/collections/minItems.js +122 -27
  12. package/lib/esm/decorators/collections/minProperties.js +132 -31
  13. package/lib/esm/decorators/common/additionalProperties.js +59 -4
  14. package/lib/esm/decorators/common/allOf.js +61 -6
  15. package/lib/esm/decorators/common/allow.js +56 -12
  16. package/lib/esm/decorators/common/any.js +58 -18
  17. package/lib/esm/decorators/common/anyOf.js +65 -9
  18. package/lib/esm/decorators/common/const.js +72 -30
  19. package/lib/esm/decorators/common/customKey.js +132 -12
  20. package/lib/esm/decorators/common/default.js +85 -19
  21. package/lib/esm/decorators/common/discriminatorKey.js +123 -0
  22. package/lib/esm/decorators/common/errorMsg.js +48 -2
  23. package/lib/esm/decorators/common/example.js +68 -6
  24. package/lib/esm/decorators/common/examples.js +99 -6
  25. package/lib/esm/decorators/common/format.js +86 -52
  26. package/lib/esm/decorators/common/nullable.js +77 -11
  27. package/lib/esm/decorators/common/oneOf.js +93 -9
  28. package/lib/esm/decorators/common/optional.js +93 -4
  29. package/lib/esm/decorators/common/property.js +42 -6
  30. package/lib/esm/decorators/common/readOnly.js +106 -5
  31. package/lib/esm/decorators/common/required.js +57 -20
  32. package/lib/esm/decorators/common/writeOnly.js +117 -5
  33. package/lib/esm/domain/JsonClassStore.js +75 -0
  34. package/lib/esm/domain/JsonDiscriminator.js +57 -0
  35. package/lib/esm/domain/JsonEntityStore.js +46 -0
  36. package/lib/esm/domain/JsonFormatTypes.js +39 -0
  37. package/lib/esm/domain/JsonLazyRef.js +33 -0
  38. package/lib/esm/domain/JsonMap.js +32 -0
  39. package/lib/esm/domain/JsonMedia.js +28 -0
  40. package/lib/esm/domain/JsonMethodStore.js +56 -0
  41. package/lib/esm/domain/JsonOperation.js +43 -0
  42. package/lib/esm/domain/JsonOperationPathsMap.js +38 -0
  43. package/lib/esm/domain/JsonOperationRoute.js +54 -0
  44. package/lib/esm/domain/JsonParameter.js +35 -0
  45. package/lib/esm/domain/JsonParameterStore.js +71 -0
  46. package/lib/esm/domain/JsonParameterTypes.js +26 -0
  47. package/lib/esm/domain/JsonPropertyStore.js +44 -0
  48. package/lib/esm/domain/JsonRequestBody.js +26 -0
  49. package/lib/esm/domain/JsonResponse.js +29 -0
  50. package/lib/esm/domain/JsonSchema.js +365 -16
  51. package/lib/esm/domain/SpecTypes.js +26 -0
  52. package/lib/esm/fn/boolean.js +39 -3
  53. package/lib/esm/fn/number.js +45 -3
  54. package/lib/esm/fn/string.js +43 -3
  55. package/lib/types/constants/OperationVerbs.d.ts +35 -0
  56. package/lib/types/constants/VendorKeys.d.ts +29 -0
  57. package/lib/types/constants/httpStatusMessages.d.ts +59 -0
  58. package/lib/types/constants/jsonSchemaProperties.d.ts +55 -0
  59. package/lib/types/decorators/class/children.d.ts +93 -5
  60. package/lib/types/decorators/class/discriminatorValue.d.ts +124 -20
  61. package/lib/types/decorators/collections/collectionContains.d.ts +91 -10
  62. package/lib/types/decorators/collections/maxItems.d.ts +97 -27
  63. package/lib/types/decorators/collections/maxProperties.d.ts +96 -30
  64. package/lib/types/decorators/collections/minItems.d.ts +122 -27
  65. package/lib/types/decorators/collections/minProperties.d.ts +132 -31
  66. package/lib/types/decorators/common/additionalProperties.d.ts +59 -4
  67. package/lib/types/decorators/common/allOf.d.ts +61 -6
  68. package/lib/types/decorators/common/allow.d.ts +56 -12
  69. package/lib/types/decorators/common/any.d.ts +58 -18
  70. package/lib/types/decorators/common/anyOf.d.ts +65 -9
  71. package/lib/types/decorators/common/const.d.ts +72 -30
  72. package/lib/types/decorators/common/customKey.d.ts +132 -12
  73. package/lib/types/decorators/common/default.d.ts +85 -19
  74. package/lib/types/decorators/common/discriminatorKey.d.ts +123 -0
  75. package/lib/types/decorators/common/errorMsg.d.ts +48 -2
  76. package/lib/types/decorators/common/example.d.ts +68 -6
  77. package/lib/types/decorators/common/examples.d.ts +99 -6
  78. package/lib/types/decorators/common/format.d.ts +86 -52
  79. package/lib/types/decorators/common/nullable.d.ts +77 -11
  80. package/lib/types/decorators/common/oneOf.d.ts +93 -9
  81. package/lib/types/decorators/common/optional.d.ts +93 -4
  82. package/lib/types/decorators/common/property.d.ts +42 -6
  83. package/lib/types/decorators/common/readOnly.d.ts +106 -5
  84. package/lib/types/decorators/common/required.d.ts +57 -20
  85. package/lib/types/decorators/common/writeOnly.d.ts +117 -5
  86. package/lib/types/domain/JsonClassStore.d.ts +75 -0
  87. package/lib/types/domain/JsonDiscriminator.d.ts +57 -0
  88. package/lib/types/domain/JsonEntityStore.d.ts +51 -0
  89. package/lib/types/domain/JsonFormatTypes.d.ts +39 -0
  90. package/lib/types/domain/JsonLazyRef.d.ts +33 -0
  91. package/lib/types/domain/JsonMap.d.ts +32 -0
  92. package/lib/types/domain/JsonMedia.d.ts +28 -0
  93. package/lib/types/domain/JsonMethodStore.d.ts +66 -0
  94. package/lib/types/domain/JsonOperation.d.ts +51 -0
  95. package/lib/types/domain/JsonOperationPathsMap.d.ts +38 -0
  96. package/lib/types/domain/JsonOperationRoute.d.ts +54 -0
  97. package/lib/types/domain/JsonParameter.d.ts +35 -0
  98. package/lib/types/domain/JsonParameterStore.d.ts +97 -0
  99. package/lib/types/domain/JsonParameterTypes.d.ts +26 -0
  100. package/lib/types/domain/JsonPropertyStore.d.ts +44 -0
  101. package/lib/types/domain/JsonRequestBody.d.ts +31 -0
  102. package/lib/types/domain/JsonResponse.d.ts +34 -0
  103. package/lib/types/domain/JsonSchema.d.ts +422 -19
  104. package/lib/types/domain/SpecTypes.d.ts +26 -0
  105. package/lib/types/domain/types.d.ts +90 -0
  106. package/lib/types/fn/boolean.d.ts +39 -3
  107. package/lib/types/fn/number.d.ts +45 -3
  108. package/lib/types/fn/string.d.ts +43 -3
  109. package/lib/types/interfaces/IgnoreCallback.d.ts +24 -0
  110. package/lib/types/interfaces/JsonHookContext.d.ts +31 -0
  111. package/lib/types/interfaces/JsonOpenSpec.d.ts +33 -0
  112. package/lib/types/interfaces/JsonSchemaOptions.d.ts +26 -0
  113. package/package.json +7 -7
@@ -1,48 +1,118 @@
1
1
  /**
2
- * The value `maxItems` MUST be a non-negative integer.
2
+ * Sets the maximum number of items allowed in an array.
3
3
  *
4
- * An array instance is valid against `maxItems` if its size is less than, or equal to, the value of this keyword.
4
+ * The `@MaxItems()` decorator validates that an array has at most the specified number
5
+ * of elements. This is useful for enforcing size limits on collections to prevent
6
+ * excessive data, manage performance, or enforce business rules.
5
7
  *
6
- * :: warning
7
- * The value `maxItems` MUST be a non-negative integer.
8
- * :::
9
- *
10
- * :: warning
11
- * This decorator will be removed in v7.
12
- * For v6 user, use @@MaxItems@@ from @tsed/schema instead of @tsed/platform-http.
13
- * :::
14
- *
15
- * ## Example
8
+ * ### Basic Usage
16
9
  *
17
10
  * ```typescript
18
- * class Model {
19
- * @CollectionOf(String)
20
- * @MaxItems(10)
21
- * property: string[];
11
+ * class UserModel {
12
+ * @CollectionOf(String)
13
+ * @MaxItems(5)
14
+ * tags: string[];
15
+ * // Maximum 5 tags allowed
22
16
  * }
23
17
  * ```
24
18
  *
25
- * Will produce:
26
- *
19
+ * Generated schema:
27
20
  * ```json
28
21
  * {
29
22
  * "type": "object",
30
23
  * "properties": {
31
- * "property": {
32
- * "type": "number",
33
- * "maxItems": 10
24
+ * "tags": {
25
+ * "type": "array",
26
+ * "maxItems": 5,
27
+ * "items": {
28
+ * "type": "string"
29
+ * }
34
30
  * }
35
31
  * }
36
32
  * }
37
33
  * ```
38
34
  *
39
- * @param {number} maxItems
35
+ * ### With MinItems - Range Validation
36
+ *
37
+ * ```typescript
38
+ * class TeamModel {
39
+ * @CollectionOf(String)
40
+ * @MinItems(1)
41
+ * @MaxItems(10)
42
+ * members: string[];
43
+ * // Must have between 1 and 10 members
44
+ * }
45
+ * ```
46
+ *
47
+ * ### API Rate Limiting
48
+ *
49
+ * ```typescript
50
+ * class BulkRequest {
51
+ * @CollectionOf(Number)
52
+ * @MaxItems(100)
53
+ * ids: number[];
54
+ * // Limit bulk operations to 100 items
55
+ * }
56
+ * ```
57
+ *
58
+ * ### File Uploads
59
+ *
60
+ * ```typescript
61
+ * class FileUpload {
62
+ * @CollectionOf(Object)
63
+ * @MaxItems(5)
64
+ * attachments: File[];
65
+ * // Maximum 5 file attachments
66
+ * }
67
+ * ```
68
+ *
69
+ * ### Validation Examples
70
+ *
71
+ * ```typescript
72
+ * @MaxItems(3)
73
+ * items: string[];
74
+ *
75
+ * // Valid:
76
+ * [] // 0 items (≤ 3)
77
+ * ["a"] // 1 item (≤ 3)
78
+ * ["a", "b", "c"] // 3 items (≤ 3)
79
+ *
80
+ * // Invalid:
81
+ * ["a", "b", "c", "d"] // 4 items (> 3)
82
+ * ```
83
+ *
84
+ * ### Use Cases
85
+ *
86
+ * - **Performance**: Limit collection sizes to prevent memory issues
87
+ * - **Business Rules**: Enforce maximum quantities (cart items, selections)
88
+ * - **API Protection**: Prevent abuse with excessive bulk requests
89
+ * - **UI Constraints**: Match front-end limitations (max selections)
90
+ * - **Data Quality**: Encourage focused, manageable data sets
91
+ *
92
+ * ### Combining with Other Validators
93
+ *
94
+ * ```typescript
95
+ * class SearchQuery {
96
+ * @CollectionOf(String)
97
+ * @MinItems(1)
98
+ * @MaxItems(10)
99
+ * @UniqueItems()
100
+ * keywords: string[];
101
+ * // 1-10 unique search keywords
102
+ * }
103
+ * ```
104
+ *
105
+ * ### Important Notes
106
+ *
107
+ * - The value must be a **non-negative integer** (0 or greater)
108
+ * - Throws an error if a negative value is provided
109
+ * - Empty arrays (length 0) always pass maxItems validation
110
+ * - Can be combined with custom error messages using ajv-errors
111
+ *
112
+ * @param maxItems - Maximum number of items allowed (must be non-negative)
113
+ *
40
114
  * @decorator
41
115
  * @validation
42
- * @swagger
43
- * @schema
44
- * @input
45
- * @collections
46
- * @ajv-errors
116
+ * @public
47
117
  */
48
118
  export declare const MaxItems: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(maxItems: number) => (...args: any[]) => any>;
@@ -1,48 +1,43 @@
1
1
  /**
2
- * An object instance is valid against `maxProperties` if its number of properties is less than, or equal to, the value of this keyword.
2
+ * Sets the maximum number of properties allowed on an object.
3
3
  *
4
- * ::: warning
5
- * The value of this keyword MUST be a non-negative integer.
6
- * :::
4
+ * The `@MaxProperties()` decorator validates that an object has at most the specified
5
+ * number of properties. This is useful for limiting dynamic object sizes, preventing
6
+ * excessive data structures, or enforcing schema constraints on flexible objects.
7
7
  *
8
- * ::: warning
9
- * This decorator will be removed in v7.
10
- * For v6 user, use @@MaxProperties@@ from @tsed/schema instead of @tsed/platform-http.
11
- * :::
8
+ * ### On Property
12
9
  *
13
- * ## Example
14
- * ### On prop
15
10
  * ```typescript
16
- * class Model {
17
- * @MaxProperties(10)
18
- * property: any;
11
+ * class ConfigModel {
12
+ * @MaxProperties(5)
13
+ * metadata: Record<string, any>;
14
+ * // Object can have at most 5 properties
19
15
  * }
20
16
  * ```
21
17
  *
22
- * Will produce:
23
- *
18
+ * Generated schema:
24
19
  * ```json
25
20
  * {
26
21
  * "type": "object",
27
22
  * "properties": {
28
- * "property": {
29
- * "type": "any",
30
- * "maxProperties": 10
23
+ * "metadata": {
24
+ * "type": "object",
25
+ * "maxProperties": 5
31
26
  * }
32
27
  * }
33
28
  * }
34
29
  * ```
35
30
  *
36
- * ### On class
31
+ * ### On Class
37
32
  *
38
33
  * ```typescript
39
34
  * @MaxProperties(10)
40
- * class Model {
35
+ * class DynamicModel {
36
+ * // Class instances can have at most 10 properties total
41
37
  * }
42
38
  * ```
43
39
  *
44
- * Will produce:
45
- *
40
+ * Generated schema:
46
41
  * ```json
47
42
  * {
48
43
  * "type": "object",
@@ -53,19 +48,90 @@
53
48
  * ### On Parameter
54
49
  *
55
50
  * ```typescript
51
+ * @Controller("/api")
52
+ * class ApiController {
53
+ * @Post("/config")
54
+ * updateConfig(
55
+ * @BodyParams() @MaxProperties(10) config: any
56
+ * ) {
57
+ * // Config object limited to 10 properties
58
+ * }
59
+ * }
60
+ * ```
61
+ *
62
+ * ### With MinProperties - Range Validation
63
+ *
64
+ * ```typescript
65
+ * class FilterModel {
66
+ * @MinProperties(1)
67
+ * @MaxProperties(5)
68
+ * filters: Record<string, string>;
69
+ * // Must have 1-5 filter properties
70
+ * }
71
+ * ```
72
+ *
73
+ * ### Dynamic Objects
74
+ *
75
+ * ```typescript
76
+ * class UserPreferences {
77
+ * @MaxProperties(20)
78
+ * @AdditionalProperties({ type: "string" })
79
+ * settings: Record<string, string>;
80
+ * // Up to 20 custom settings, all string values
81
+ * }
82
+ * ```
83
+ *
84
+ * ### Validation Examples
85
+ *
86
+ * ```typescript
87
+ * @MaxProperties(2)
88
+ * data: object;
89
+ *
90
+ * // Valid:
91
+ * {} // 0 properties (≤ 2)
92
+ * { a: 1 } // 1 property (≤ 2)
93
+ * { a: 1, b: 2 } // 2 properties (≤ 2)
94
+ *
95
+ * // Invalid:
96
+ * { a: 1, b: 2, c: 3 } // 3 properties (> 2)
97
+ * ```
98
+ *
99
+ * ### Use Cases
100
+ *
101
+ * - **API Rate Limiting**: Restrict filter/query parameter counts
102
+ * - **Performance**: Prevent overly complex objects
103
+ * - **Schema Constraints**: Limit dynamic data structures
104
+ * - **Configuration**: Cap number of custom settings
105
+ * - **Security**: Prevent payload bloat attacks
56
106
  *
57
- * class Model {
58
- * method(@Any() @MaxProperties(10) obj: any){}
107
+ * ### Flexible Schemas
108
+ *
109
+ * ```typescript
110
+ * class ExtensibleModel {
111
+ * @Property()
112
+ * id: string;
113
+ *
114
+ * @Property()
115
+ * name: string;
116
+ *
117
+ * @MaxProperties(5)
118
+ * @AdditionalProperties(true)
119
+ * // 2 defined properties + up to 3 additional properties
59
120
  * }
60
121
  * ```
61
122
  *
62
- * @param {number} maxProperties The maximum properties allowed on the given object
123
+ * ### Important Notes
124
+ *
125
+ * - The value must be a **non-negative integer** (0 or greater)
126
+ * - Throws an error if a negative value is provided
127
+ * - Empty objects (`{}`) always pass maxProperties validation
128
+ * - Counts all properties, including inherited and additional ones
129
+ * - Can be combined with custom error messages using ajv-errors
130
+ *
131
+ * @param maxProperties - Maximum number of properties allowed (must be non-negative)
132
+ *
63
133
  * @decorator
64
134
  * @validation
65
- * @swagger
66
- * @schema
67
- * @input
68
- * @collections
69
- * @ajv-errors
135
+ * @public
70
136
  */
71
137
  export declare const MaxProperties: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(maxProperties: number) => (...args: any[]) => any>;
@@ -1,37 +1,29 @@
1
1
  /**
2
- * An array instance is valid against `minItems` if its size is greater than, or equal to, the value of this keyword.
2
+ * Sets the minimum number of items required in an array.
3
3
  *
4
- * ::: warning
5
- * The value `minItems` MUST be a non-negative integer.
6
- * :::
4
+ * The `@MinItems()` decorator validates that an array has at least the specified number
5
+ * of elements. This is useful for ensuring required data is provided, enforcing business
6
+ * rules, or guaranteeing minimum quantities.
7
7
  *
8
- * ::: tip
9
- * Omitting this keyword has the same behavior as a value of 0.
10
- * :::
11
- *
12
- * ::: warning
13
- * For v6 user, use @@MinItems@@ from @tsed/schema instead of @tsed/platform-http.
14
- * :::
15
- *
16
- * ## Example
8
+ * ### Basic Usage
17
9
  *
18
10
  * ```typescript
19
- * class Model {
20
- * @CollectionOf(String)
21
- * @MinItems(10)
22
- * property: string[];
11
+ * class OrderModel {
12
+ * @CollectionOf(String)
13
+ * @MinItems(1)
14
+ * items: string[];
15
+ * // Order must have at least 1 item
23
16
  * }
24
17
  * ```
25
18
  *
26
- * Will produce:
27
- *
19
+ * Generated schema:
28
20
  * ```json
29
21
  * {
30
22
  * "type": "object",
31
23
  * "properties": {
32
- * "property": {
24
+ * "items": {
33
25
  * "type": "array",
34
- * "minItems": 10,
26
+ * "minItems": 1,
35
27
  * "items": {
36
28
  * "type": "string"
37
29
  * }
@@ -40,13 +32,116 @@
40
32
  * }
41
33
  * ```
42
34
  *
43
- * @param {number} minItems
35
+ * ### With MaxItems - Range Validation
36
+ *
37
+ * ```typescript
38
+ * class VotingModel {
39
+ * @CollectionOf(String)
40
+ * @MinItems(3)
41
+ * @MaxItems(10)
42
+ * candidates: string[];
43
+ * // Must have between 3 and 10 candidates
44
+ * }
45
+ * ```
46
+ *
47
+ * ### Required Selections
48
+ *
49
+ * ```typescript
50
+ * class SurveyResponse {
51
+ * @CollectionOf(String)
52
+ * @MinItems(1)
53
+ * selectedOptions: string[];
54
+ * // User must select at least one option
55
+ * }
56
+ * ```
57
+ *
58
+ * ### Business Rules
59
+ *
60
+ * ```typescript
61
+ * class TeamCreation {
62
+ * @CollectionOf(String)
63
+ * @MinItems(2)
64
+ * memberIds: string[];
65
+ * // Team requires minimum 2 members
66
+ * }
67
+ * ```
68
+ *
69
+ * ### Validation Examples
70
+ *
71
+ * ```typescript
72
+ * @MinItems(2)
73
+ * items: string[];
74
+ *
75
+ * // Valid:
76
+ * ["a", "b"] // 2 items (≥ 2)
77
+ * ["a", "b", "c"] // 3 items (≥ 2)
78
+ *
79
+ * // Invalid:
80
+ * [] // 0 items (< 2)
81
+ * ["a"] // 1 item (< 2)
82
+ * ```
83
+ *
84
+ * ### Use Cases
85
+ *
86
+ * - **Required Data**: Ensure minimum data is provided
87
+ * - **Business Logic**: Enforce minimum quantities (team size, votes)
88
+ * - **Data Quality**: Prevent submission with insufficient information
89
+ * - **User Input**: Require multiple selections or answers
90
+ * - **Validation**: Ensure arrays are not empty when data is expected
91
+ *
92
+ * ### Non-Empty Arrays
93
+ *
94
+ * ```typescript
95
+ * class CommentModel {
96
+ * @CollectionOf(String)
97
+ * @MinItems(1)
98
+ * tags: string[];
99
+ * // Prevent empty tag arrays
100
+ * }
101
+ * ```
102
+ *
103
+ * ### Combining with Uniqueness
104
+ *
105
+ * ```typescript
106
+ * class CategoryModel {
107
+ * @CollectionOf(String)
108
+ * @MinItems(2)
109
+ * @UniqueItems()
110
+ * subcategories: string[];
111
+ * // Must have at least 2 unique subcategories
112
+ * }
113
+ * ```
114
+ *
115
+ * ### Important Notes
116
+ *
117
+ * - The value must be a **non-negative integer** (0 or greater)
118
+ * - Throws an error if a negative value is provided
119
+ * - Omitting `@MinItems()` is equivalent to `@MinItems(0)` (no minimum)
120
+ * - Can be combined with custom error messages using ajv-errors
121
+ * - Arrays with exactly minItems elements are valid (inclusive)
122
+ *
123
+ * ### Default Behavior
124
+ *
125
+ * Without `@MinItems()`, arrays can be empty:
126
+ * ```typescript
127
+ * @CollectionOf(String)
128
+ * tags: string[];
129
+ * // Valid: [], ["tag1"], ["tag1", "tag2"], etc.
130
+ * ```
131
+ *
132
+ * With `@MinItems(1)`, empty arrays are rejected:
133
+ * ```typescript
134
+ * @CollectionOf(String)
135
+ * @MinItems(1)
136
+ * tags: string[];
137
+ * // Invalid: []
138
+ * // Valid: ["tag1"], ["tag1", "tag2"], etc.
139
+ * ```
140
+ *
141
+ * @param minItems - Minimum number of items required (must be non-negative)
142
+ *
44
143
  * @decorator
45
144
  * @validation
46
- * @swagger
47
- * @schema
48
- * @input
49
- * @collections
50
- * @ajv-errors
145
+ * @public
51
146
  */
52
147
  export declare const MinItems: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(minItems: number) => (...args: any[]) => any>;
@@ -1,70 +1,171 @@
1
1
  /**
2
- * An object instance is valid against `minProperties` if its number of properties is less than, or equal to, the value of this keyword.
2
+ * Sets the minimum number of properties required on an object.
3
3
  *
4
- * ::: warning
5
- * The value of this keyword MUST be a non-negative integer.
6
- * :::
4
+ * The `@MinProperties()` decorator validates that an object has at least the specified
5
+ * number of properties. This is useful for ensuring objects aren't empty, enforcing
6
+ * minimum data requirements, or validating that dynamic objects have sufficient content.
7
7
  *
8
- * ::: warning
9
- * For v6 user, use @@MinProperties@@ from @tsed/schema instead of @tsed/platform-http.
10
- * :::
8
+ * ### On Property
11
9
  *
12
- * ## Example
13
- * ### On prop
14
10
  * ```typescript
15
- * class Model {
16
- * @MinProperties(10)
17
- * property: any;
11
+ * class DataModel {
12
+ * @MinProperties(1)
13
+ * attributes: Record<string, any>;
14
+ * // Object must have at least 1 property
18
15
  * }
19
16
  * ```
20
17
  *
21
- * Will produce:
22
- *
18
+ * Generated schema:
23
19
  * ```json
24
20
  * {
25
21
  * "type": "object",
26
22
  * "properties": {
27
- * "property": {
28
- * "type": "any",
29
- * "minProperties": 10
23
+ * "attributes": {
24
+ * "type": "object",
25
+ * "minProperties": 1
30
26
  * }
31
27
  * }
32
28
  * }
33
29
  * ```
34
30
  *
35
- * ### On class
31
+ * ### On Class
36
32
  *
37
33
  * ```typescript
38
- * @MinProperties(10)
39
- * class Model {
34
+ * @MinProperties(2)
35
+ * class RequiredDataModel {
36
+ * // Class instances must have at least 2 properties
40
37
  * }
41
38
  * ```
42
39
  *
43
- * Will produce:
44
- *
40
+ * Generated schema:
45
41
  * ```json
46
42
  * {
47
43
  * "type": "object",
48
- * "minProperties": 10
44
+ * "minProperties": 2
49
45
  * }
50
46
  * ```
51
47
  *
52
48
  * ### On Parameter
53
49
  *
54
50
  * ```typescript
51
+ * @Controller("/api")
52
+ * class ApiController {
53
+ * @Post("/filters")
54
+ * search(
55
+ * @BodyParams() @MinProperties(1) filters: any
56
+ * ) {
57
+ * // Filters object must have at least 1 property
58
+ * }
59
+ * }
60
+ * ```
61
+ *
62
+ * ### With MaxProperties - Range Validation
63
+ *
64
+ * ```typescript
65
+ * class MetadataModel {
66
+ * @MinProperties(2)
67
+ * @MaxProperties(10)
68
+ * metadata: Record<string, string>;
69
+ * // Must have between 2 and 10 properties
70
+ * }
71
+ * ```
72
+ *
73
+ * ### Non-Empty Objects
74
+ *
75
+ * ```typescript
76
+ * class SearchCriteria {
77
+ * @MinProperties(1)
78
+ * criteria: Record<string, any>;
79
+ * // Prevent empty search criteria objects
80
+ * }
81
+ * ```
82
+ *
83
+ * ### Dynamic Configuration
84
+ *
85
+ * ```typescript
86
+ * class PluginConfig {
87
+ * @MinProperties(1)
88
+ * @AdditionalProperties({ type: "string" })
89
+ * options: Record<string, string>;
90
+ * // At least 1 configuration option required
91
+ * }
92
+ * ```
93
+ *
94
+ * ### Validation Examples
95
+ *
96
+ * ```typescript
97
+ * @MinProperties(2)
98
+ * data: object;
55
99
  *
56
- * class Model {
57
- * method(@Any() @MinProperties(10) obj: any){}
100
+ * // Valid:
101
+ * { a: 1, b: 2 } // 2 properties (≥ 2)
102
+ * { a: 1, b: 2, c: 3 } // 3 properties (≥ 2)
103
+ *
104
+ * // Invalid:
105
+ * {} // 0 properties (< 2)
106
+ * { a: 1 } // 1 property (< 2)
107
+ * ```
108
+ *
109
+ * ### Use Cases
110
+ *
111
+ * - **Required Data**: Ensure objects have minimum content
112
+ * - **Non-Empty Objects**: Prevent empty dynamic objects
113
+ * - **Business Rules**: Enforce minimum configuration requirements
114
+ * - **API Validation**: Require sufficient filter/search criteria
115
+ * - **Data Quality**: Ensure objects contain meaningful data
116
+ *
117
+ * ### Filter Validation
118
+ *
119
+ * ```typescript
120
+ * class QueryModel {
121
+ * @MinProperties(1)
122
+ * filters: Record<string, string>;
123
+ * // Must specify at least one filter
58
124
  * }
59
125
  * ```
60
126
  *
61
- * @param {number} minProperties The minimum properties allowed on the object.
127
+ * ### Combining with AdditionalProperties
128
+ *
129
+ * ```typescript
130
+ * class FlexibleModel {
131
+ * @Property()
132
+ * id: string;
133
+ *
134
+ * @MinProperties(3)
135
+ * @AdditionalProperties({ type: "string" })
136
+ * // 1 defined property + at least 2 additional properties = 3 minimum
137
+ * }
138
+ * ```
139
+ *
140
+ * ### Important Notes
141
+ *
142
+ * - The value must be a **non-negative integer** (0 or greater)
143
+ * - Throws an error if a negative value is provided
144
+ * - Omitting `@MinProperties()` is equivalent to `@MinProperties(0)` (no minimum)
145
+ * - Counts all properties, including defined and additional ones
146
+ * - Objects with exactly minProperties count are valid (inclusive)
147
+ * - Can be combined with custom error messages using ajv-errors
148
+ *
149
+ * ### Default Behavior
150
+ *
151
+ * Without `@MinProperties()`, empty objects are valid:
152
+ * ```typescript
153
+ * data: Record<string, any>;
154
+ * // Valid: {}, { a: 1 }, { a: 1, b: 2 }, etc.
155
+ * ```
156
+ *
157
+ * With `@MinProperties(1)`, empty objects are rejected:
158
+ * ```typescript
159
+ * @MinProperties(1)
160
+ * data: Record<string, any>;
161
+ * // Invalid: {}
162
+ * // Valid: { a: 1 }, { a: 1, b: 2 }, etc.
163
+ * ```
164
+ *
165
+ * @param minProperties - Minimum number of properties required (must be non-negative)
166
+ *
62
167
  * @decorator
63
168
  * @validation
64
- * @swagger
65
- * @schema
66
- * @input
67
- * @collections
68
- * @ajv-errors
169
+ * @public
69
170
  */
70
171
  export declare const MinProperties: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(minProperties: number) => (...args: any[]) => any>;