@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,15 +1,84 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * Set a custom key on JsonSchema that is not a part of the official spec.
3
+ * Adds a custom key-value pair to the JSON Schema that is not part of the official spec.
4
4
  *
5
- * This custom key can only be displayed if the @@getJsonSchema@@ is called with `{customKeys: true}`.
5
+ * The `@CustomKey()` decorator allows adding vendor-specific extensions or custom metadata
6
+ * to schemas. These custom keys are only included in the generated schema when explicitly
7
+ * requested with the `customKeys: true` option in `getJsonSchema()`.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * class UserModel {
13
+ * @CustomKey("x-internal-id", "USER_001")
14
+ * @Property()
15
+ * username: string;
16
+ * }
17
+ * ```
18
+ *
19
+ * ### Vendor Extensions
20
+ *
21
+ * Following OpenAPI conventions, use `x-` prefix for custom extensions:
22
+ *
23
+ * ```typescript
24
+ * class ApiModel {
25
+ * @CustomKey("x-visibility", "internal")
26
+ * @CustomKey("x-deprecated-by", "newField")
27
+ * @Property()
28
+ * oldField: string;
29
+ * }
30
+ * ```
31
+ *
32
+ * ### Documentation Metadata
33
+ *
34
+ * ```typescript
35
+ * class ProductModel {
36
+ * @CustomKey("x-example-source", "marketing-team")
37
+ * @CustomKey("x-last-reviewed", "2024-01-15")
38
+ * @Property()
39
+ * description: string;
40
+ * }
41
+ * ```
42
+ *
43
+ * ### Integration Hints
44
+ *
45
+ * ```typescript
46
+ * class DataModel {
47
+ * @CustomKey("x-database-column", "user_full_name")
48
+ * @CustomKey("x-searchable", true)
49
+ * @Property()
50
+ * fullName: string;
51
+ * }
52
+ * ```
53
+ *
54
+ * ### Retrieving Custom Keys
55
+ *
56
+ * Custom keys must be explicitly requested:
57
+ *
58
+ * ```typescript
59
+ * import { getJsonSchema } from "@tsed/schema";
60
+ *
61
+ * const schema = getJsonSchema(UserModel, { customKeys: true });
62
+ * // Schema will include x-internal-id and other custom keys
63
+ *
64
+ * const standardSchema = getJsonSchema(UserModel);
65
+ * // Custom keys are omitted by default
66
+ * ```
67
+ *
68
+ * ### Use Cases
69
+ *
70
+ * - **OpenAPI Extensions**: Add vendor-specific OpenAPI extensions
71
+ * - **Tool Integration**: Metadata for code generators or documentation tools
72
+ * - **Internal Tracking**: Development or operational metadata
73
+ * - **Feature Flags**: Schema-level feature flag information
74
+ * - **Database Mapping**: ORM or database column hints
75
+ *
76
+ * @param key - The custom key name (use `x-` prefix for vendor extensions)
77
+ * @param value - The value to associate with the key
6
78
  *
7
- * @returns {Function}
8
79
  * @decorator
9
80
  * @validation
10
- * @property
11
- * @parameter
12
- * @schema
81
+ * @public
13
82
  */
14
83
  export function CustomKey(key, value) {
15
84
  return JsonEntityFn((store) => {
@@ -17,16 +86,67 @@ export function CustomKey(key, value) {
17
86
  });
18
87
  }
19
88
  /**
20
- * Set a group of custom keys on JsonSchema that is not a part of the official spec.
89
+ * Adds multiple custom key-value pairs to the JSON Schema in one decorator.
90
+ *
91
+ * The `@CustomKeys()` decorator is a convenience function for adding multiple custom
92
+ * keys at once. Like `@CustomKey()`, these keys are only included when explicitly
93
+ * requested with `customKeys: true`.
94
+ *
95
+ * ### Basic Usage
96
+ *
97
+ * ```typescript
98
+ * class ProductModel {
99
+ * @CustomKeys({
100
+ * "x-internal-code": "PROD-123",
101
+ * "x-category": "electronics",
102
+ * "x-priority": "high"
103
+ * })
104
+ * @Property()
105
+ * name: string;
106
+ * }
107
+ * ```
108
+ *
109
+ * ### Multiple Vendor Extensions
110
+ *
111
+ * ```typescript
112
+ * class ApiEndpoint {
113
+ * @CustomKeys({
114
+ * "x-rate-limit": 100,
115
+ * "x-requires-auth": true,
116
+ * "x-cache-ttl": 3600,
117
+ * "x-deprecated": false
118
+ * })
119
+ * @Property()
120
+ * endpoint: string;
121
+ * }
122
+ * ```
123
+ *
124
+ * ### Equivalent to Multiple @CustomKey
125
+ *
126
+ * These are equivalent:
127
+ *
128
+ * ```typescript
129
+ * // Using @CustomKeys
130
+ * @CustomKeys({ "x-foo": "bar", "x-baz": "qux" })
131
+ * field: string;
132
+ *
133
+ * // Using multiple @CustomKey
134
+ * @CustomKey("x-foo", "bar")
135
+ * @CustomKey("x-baz", "qux")
136
+ * field: string;
137
+ * ```
138
+ *
139
+ * ### Use Cases
140
+ *
141
+ * - **Bulk Metadata**: Add multiple related custom properties efficiently
142
+ * - **Configuration**: Group related custom configuration values
143
+ * - **Tool Directives**: Multiple hints for code generation or documentation
21
144
  *
22
- * This custom key can only be displayed if the @@getJsonSchema@@ is called with `{customKeys: true}`.
145
+ * @param obj - Object containing custom key-value pairs
23
146
  *
24
- * @returns {Function}
25
147
  * @decorator
26
148
  * @validation
27
- * @property
28
- * @parameter
29
- * @schema
149
+ * @public
30
150
  */
31
151
  export function CustomKeys(obj) {
32
152
  return JsonEntityFn((store) => {
@@ -1,43 +1,109 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * There are no restrictions placed on the value of this keyword.
3
+ * Specifies a default value for a property in the JSON Schema.
4
4
  *
5
- * ::: warning
6
- * For v6 user, use @@Default@@ from @tsed/schema instead of @tsed/platform-http.
7
- * :::
5
+ * The `@Default()` decorator sets the default value that should be used when a property
6
+ * is not provided in the input. This is primarily used for documentation in OpenAPI specs
7
+ * and can be used by validation libraries that support default value insertion.
8
8
  *
9
- * This keyword can be used to supply a default JSON value associated with a particular schema.
10
- * It is RECOMMENDED that a default value be valid against the associated schema.
11
- *
12
- * ## Example
9
+ * ### Basic Usage
13
10
  *
14
11
  * ```typescript
15
- * class Model {
16
- * @Default("10")
17
- * property: string = "10";
12
+ * class UserModel {
13
+ * @Default("guest")
14
+ * role: string = "guest";
15
+ *
16
+ * @Default(0)
17
+ * loginCount: number = 0;
18
+ *
19
+ * @Default(true)
20
+ * active: boolean = true;
18
21
  * }
19
22
  * ```
20
23
  *
21
- * Will produce:
22
- *
24
+ * Generated schema:
23
25
  * ```json
24
26
  * {
25
27
  * "type": "object",
26
28
  * "properties": {
27
- * "property": {
29
+ * "role": {
28
30
  * "type": "string",
29
- * "default": "10"
31
+ * "default": "guest"
32
+ * },
33
+ * "loginCount": {
34
+ * "type": "integer",
35
+ * "default": 0
36
+ * },
37
+ * "active": {
38
+ * "type": "boolean",
39
+ * "default": true
30
40
  * }
31
41
  * }
32
42
  * }
33
43
  * ```
34
44
  *
35
- * @param {string | number | boolean | {}} defaultValue
45
+ * ### With Objects
46
+ *
47
+ * ```typescript
48
+ * class ConfigModel {
49
+ * @Default({ theme: "light", lang: "en" })
50
+ * preferences: object = { theme: "light", lang: "en" };
51
+ * }
52
+ * ```
53
+ *
54
+ * ### With Arrays
55
+ *
56
+ * ```typescript
57
+ * class ListModel {
58
+ * @Default([])
59
+ * items: string[] = [];
60
+ * }
61
+ * ```
62
+ *
63
+ * ### Dynamic Defaults with Functions
64
+ *
65
+ * ```typescript
66
+ * class TimestampModel {
67
+ * @Default(() => new Date().toISOString())
68
+ * createdAt: string;
69
+ * // Default value computed at schema generation time
70
+ * }
71
+ * ```
72
+ *
73
+ * ### Use Cases
74
+ *
75
+ * - **Optional Configuration**: Provide sensible defaults for config properties
76
+ * - **API Documentation**: Show default values in OpenAPI/Swagger docs
77
+ * - **Form Generation**: Pre-populate form fields with default values
78
+ * - **Database Models**: Document default column values
79
+ *
80
+ * ### Important Notes
81
+ *
82
+ * - The decorator adds default info to the schema but doesn't set TypeScript property initializers
83
+ * - Recommended to match TypeScript initializer with decorator value for consistency
84
+ * - Default value should be valid according to the property's schema
85
+ * - Not all validation libraries automatically apply defaults
86
+ *
87
+ * ### With Validation
88
+ *
89
+ * ```typescript
90
+ * class PaginationParams {
91
+ * @Default(10)
92
+ * @Minimum(1)
93
+ * @Maximum(100)
94
+ * limit: number = 10;
95
+ *
96
+ * @Default(0)
97
+ * @Minimum(0)
98
+ * offset: number = 0;
99
+ * }
100
+ * ```
101
+ *
102
+ * @param defaultValue - The default value (or function returning the value)
103
+ *
36
104
  * @decorator
37
105
  * @validation
38
- * @swagger
39
- * @schema
40
- * @input
106
+ * @public
41
107
  */
42
108
  export function Default(defaultValue) {
43
109
  return JsonEntityFn((store) => {
@@ -1,6 +1,129 @@
1
1
  import { useDecorators } from "@tsed/core";
2
2
  import { JsonEntityFn } from "./jsonEntityFn.js";
3
3
  import { Property } from "./property.js";
4
+ /**
5
+ * Marks a property as the discriminator key for polymorphic type resolution.
6
+ *
7
+ * The `@DiscriminatorKey()` decorator identifies which property in a base class should
8
+ * be used to determine the concrete type in inheritance hierarchies. This is essential
9
+ * for proper serialization/deserialization of polymorphic objects and for generating
10
+ * accurate OpenAPI schemas with discriminators.
11
+ *
12
+ * ### Basic Usage
13
+ *
14
+ * ```typescript
15
+ * abstract class Animal {
16
+ * @DiscriminatorKey()
17
+ * type: string;
18
+ *
19
+ * @Property()
20
+ * name: string;
21
+ * }
22
+ *
23
+ * @DiscriminatorValue("dog")
24
+ * class Dog extends Animal {
25
+ * @Property()
26
+ * breed: string;
27
+ * }
28
+ *
29
+ * @DiscriminatorValue("cat")
30
+ * class Cat extends Animal {
31
+ * @Property()
32
+ * indoor: boolean;
33
+ * }
34
+ * ```
35
+ *
36
+ * ### How It Works
37
+ *
38
+ * When deserializing, the framework:
39
+ * 1. Reads the discriminator key property value
40
+ * 2. Maps it to the correct concrete class using `@DiscriminatorValue()`
41
+ * 3. Instantiates and validates the appropriate subclass
42
+ *
43
+ * ### With API Endpoints
44
+ *
45
+ * ```typescript
46
+ * @Controller("/animals")
47
+ * class AnimalController {
48
+ * @Post("/")
49
+ * async create(@BodyParams() animal: Animal) {
50
+ * // animal is automatically deserialized to Dog or Cat
51
+ * // based on the 'type' field in the request body
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * ### OpenAPI Generation
57
+ *
58
+ * Generates discriminator object in OpenAPI spec:
59
+ *
60
+ * ```json
61
+ * {
62
+ * "discriminator": {
63
+ * "propertyName": "type",
64
+ * "mapping": {
65
+ * "dog": "#/components/schemas/Dog",
66
+ * "cat": "#/components/schemas/Cat"
67
+ * }
68
+ * }
69
+ * }
70
+ * ```
71
+ *
72
+ * ### Payment Method Example
73
+ *
74
+ * ```typescript
75
+ * abstract class PaymentMethod {
76
+ * @DiscriminatorKey()
77
+ * method: string;
78
+ * }
79
+ *
80
+ * @DiscriminatorValue("credit_card")
81
+ * class CreditCard extends PaymentMethod {
82
+ * @Property()
83
+ * cardNumber: string;
84
+ *
85
+ * @Property()
86
+ * expiryDate: string;
87
+ * }
88
+ *
89
+ * @DiscriminatorValue("bank_transfer")
90
+ * class BankTransfer extends PaymentMethod {
91
+ * @Property()
92
+ * iban: string;
93
+ *
94
+ * @Property()
95
+ * bic: string;
96
+ * }
97
+ * ```
98
+ *
99
+ * ### Use Cases
100
+ *
101
+ * - **Polymorphic APIs**: Endpoints accepting multiple related types
102
+ * - **Event Systems**: Different event types with shared base structure
103
+ * - **Strategy Pattern**: Multiple implementation variants
104
+ * - **Type-Safe Deserialization**: Automatic instantiation of correct subclass
105
+ * - **OpenAPI Documentation**: Clear polymorphic type documentation
106
+ *
107
+ * ### Best Practices
108
+ *
109
+ * - Use on abstract base classes
110
+ * - Discriminator property should be required
111
+ * - Combine with `@DiscriminatorValue()` on subclasses
112
+ * - Use meaningful, stable discriminator values
113
+ * - Document discriminator values in API documentation
114
+ *
115
+ * ### Important Notes
116
+ *
117
+ * - Only one discriminator key per class hierarchy
118
+ * - The property is automatically marked with `@Property()`
119
+ * - All subclasses must have distinct `@DiscriminatorValue()` decorators
120
+ * - Discriminator values should be unique within the hierarchy
121
+ *
122
+ * @decorator
123
+ * @property
124
+ * @public
125
+ * @see DiscriminatorValue
126
+ */
4
127
  export function DiscriminatorKey() {
5
128
  return useDecorators(Property(), JsonEntityFn((store) => {
6
129
  store.parent.schema.discriminatorKey(String(store.propertyKey));
@@ -1,8 +1,54 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * Add an error message to the property.
3
+ * Adds custom error messages for validation failures using ajv-errors.
4
+ *
5
+ * The `@ErrorMsg()` decorator allows specifying custom error messages that override
6
+ * the default validation error messages. This requires the ajv-errors plugin to be
7
+ * configured with your AJV validator.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * class UserModel {
13
+ * @ErrorMsg({ required: "Username is required" })
14
+ * @Required()
15
+ * username: string;
16
+ * }
17
+ * ```
18
+ *
19
+ * ### Multiple Validation Errors
20
+ *
21
+ * ```typescript
22
+ * class PasswordModel {
23
+ * @ErrorMsg({
24
+ * required: "Password is required",
25
+ * minLength: "Password must be at least 8 characters",
26
+ * pattern: "Password must contain letters and numbers"
27
+ * })
28
+ * @Required()
29
+ * @MinLength(8)
30
+ * @Pattern(/^(?=.*[A-Za-z])(?=.*\d)/)
31
+ * password: string;
32
+ * }
33
+ * ```
34
+ *
35
+ * ### Use Cases
36
+ *
37
+ * - **User-Friendly Messages**: Replace technical validation errors with clear messages
38
+ * - **Localization**: Provide translated error messages
39
+ * - **Business Context**: Add domain-specific error descriptions
40
+ * - **API Consistency**: Standardize error message formats
41
+ *
42
+ * ### Important Notes
43
+ *
44
+ * - Requires ajv-errors plugin to be installed and configured
45
+ * - Keys should match the validation keywords (required, minLength, etc.)
46
+ * - Messages are stored as custom schema keys
47
+ *
48
+ * @param obj - Object mapping validation keywords to custom error messages
49
+ *
4
50
  * @decorator
5
- * @ajv
51
+ * @public
6
52
  */
7
53
  export function ErrorMsg(obj) {
8
54
  return JsonEntityFn((store) => {
@@ -1,13 +1,75 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * Add an example metadata on the decorated element.
3
+ * Adds example values to the schema for documentation purposes.
4
+ *
5
+ * The `@Example()` decorator provides sample values that appear in OpenAPI/Swagger
6
+ * documentation, helping API consumers understand expected data formats. Multiple
7
+ * examples can be provided, and they're displayed in API documentation tools.
8
+ *
9
+ * ### On Properties
10
+ *
11
+ * ```typescript
12
+ * class UserModel {
13
+ * @Example("john.doe@example.com", "jane.smith@example.com")
14
+ * email: string;
15
+ * }
16
+ * ```
17
+ *
18
+ * ### On Classes
19
+ *
20
+ * ```typescript
21
+ * @Example({ name: "John", age: 30 })
22
+ * @Example({ name: "Jane", age: 25 })
23
+ * class PersonModel {
24
+ * @Property()
25
+ * name: string;
26
+ *
27
+ * @Property()
28
+ * age: number;
29
+ * }
30
+ * ```
31
+ *
32
+ * ### Complex Objects
33
+ *
34
+ * ```typescript
35
+ * class OrderModel {
36
+ * @Example(
37
+ * { id: "ORD-123", total: 99.99, items: ["item1", "item2"] },
38
+ * { id: "ORD-456", total: 149.99, items: ["item3"] }
39
+ * )
40
+ * orderData: object;
41
+ * }
42
+ * ```
43
+ *
44
+ * ### With Validation
45
+ *
46
+ * ```typescript
47
+ * class ProductModel {
48
+ * @Example("Electronics", "Clothing", "Books")
49
+ * @MinLength(3)
50
+ * @MaxLength(50)
51
+ * category: string;
52
+ * }
53
+ * ```
54
+ *
55
+ * ### Use Cases
56
+ *
57
+ * - **API Documentation**: Show realistic example values
58
+ * - **Interactive Docs**: Populate try-it-out forms with examples
59
+ * - **Code Generation**: Provide samples for client SDK generation
60
+ * - **Testing**: Reference values for test cases
61
+ *
62
+ * ### Important Notes
63
+ *
64
+ * - Examples are for documentation only, not validation
65
+ * - Multiple examples can be provided
66
+ * - Examples should match the property's type and constraints
67
+ * - Appears in OpenAPI spec under `examples` field
68
+ *
69
+ * @param examples - One or more example values
4
70
  *
5
71
  * @decorator
6
- * @swagger
7
- * @schema
8
- * @input
9
- * @methodDecorator
10
- * @classDecorator
72
+ * @public
11
73
  */
12
74
  export function Example(...examples) {
13
75
  return JsonEntityFn((store) => {
@@ -1,13 +1,106 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * Add a examples metadata on the decorated element.
3
+ * Adds named examples for parameters in OpenAPI 3.0 format.
4
+ *
5
+ * The `@Examples()` decorator provides named examples specifically for parameters,
6
+ * following the OpenAPI 3.0 specification format. Unlike `@Example()`, this accepts
7
+ * an object with named example entries, each with a value and optional description.
8
+ *
9
+ * ### Basic Usage
10
+ *
11
+ * ```typescript
12
+ * @Controller("/users")
13
+ * class UserController {
14
+ * @Get("/:id")
15
+ * async getUser(
16
+ * @Examples({
17
+ * admin: {
18
+ * value: "admin-123",
19
+ * summary: "Admin user ID"
20
+ * },
21
+ * regular: {
22
+ * value: "user-456",
23
+ * summary: "Regular user ID"
24
+ * }
25
+ * })
26
+ * @PathParams("id")
27
+ * id: string
28
+ * ) {}
29
+ * }
30
+ * ```
31
+ *
32
+ * ### Query Parameters
33
+ *
34
+ * ```typescript
35
+ * @Get("/search")
36
+ * async search(
37
+ * @Examples({
38
+ * simple: {
39
+ * value: "typescript",
40
+ * summary: "Simple keyword search"
41
+ * },
42
+ * complex: {
43
+ * value: "typescript AND nodejs",
44
+ * summary: "Boolean search query"
45
+ * }
46
+ * })
47
+ * @QueryParams("q")
48
+ * query: string
49
+ * ) {}
50
+ * ```
51
+ *
52
+ * ### With Descriptions
53
+ *
54
+ * ```typescript
55
+ * @Post("/filter")
56
+ * async filter(
57
+ * @Examples({
58
+ * basic: {
59
+ * value: { status: "active" },
60
+ * summary: "Filter by status",
61
+ * description: "Returns only active records"
62
+ * },
63
+ * advanced: {
64
+ * value: { status: "active", role: "admin" },
65
+ * summary: "Complex filter",
66
+ * description: "Combines multiple filter criteria"
67
+ * }
68
+ * })
69
+ * @BodyParams()
70
+ * filters: object
71
+ * ) {}
72
+ * ```
73
+ *
74
+ * ### Use Cases
75
+ *
76
+ * - **Interactive Docs**: Provide multiple example scenarios in Swagger UI
77
+ * - **API Education**: Show different use cases with descriptions
78
+ * - **Testing**: Reference examples for integration tests
79
+ * - **Client Generation**: Provide varied examples for SDK documentation
80
+ *
81
+ * ### OpenAPI 3.0 Format
82
+ *
83
+ * Generates:
84
+ * ```json
85
+ * {
86
+ * "examples": {
87
+ * "admin": {
88
+ * "value": "admin-123",
89
+ * "summary": "Admin user ID"
90
+ * }
91
+ * }
92
+ * }
93
+ * ```
94
+ *
95
+ * ### vs @Example
96
+ *
97
+ * - `@Examples()`: Named examples with summaries/descriptions (OpenAPI 3.0)
98
+ * - `@Example()`: Simple array of values
99
+ *
100
+ * @param examples - Object mapping names to example definitions
4
101
  *
5
102
  * @decorator
6
- * @swagger
7
- * @schema
8
- * @input
9
- * @methodDecorator
10
- * @classDecorator
103
+ * @public
11
104
  */
12
105
  export function Examples(examples) {
13
106
  return JsonEntityFn((store) => {