@tsed/schema 8.19.2 → 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
@@ -10,15 +10,86 @@ import { Discriminator } from "./JsonDiscriminator.js";
10
10
  import { JsonFormatTypes } from "./JsonFormatTypes.js";
11
11
  import { JsonLazyRef } from "./JsonLazyRef.js";
12
12
  import type { Infer, PropsToShape, UnionToIntersection } from "./types.js";
13
+ /**
14
+ * Extended JSON Schema object supporting TypeScript types and Ts.ED enhancements.
15
+ *
16
+ * This interface extends the standard JSON Schema 7 specification with additional
17
+ * type flexibility, allowing TypeScript classes and types to be used directly
18
+ * in schema definitions.
19
+ *
20
+ * @public
21
+ */
13
22
  export interface JsonSchemaObject extends Omit<JSONSchema7, "type" | "additionalProperties" | "items" | "pattern"> {
14
23
  type?: JSONSchema7["type"] | Type | null | (String | null | Date | Number | Object | Boolean)[];
15
24
  additionalProperties?: JsonSchemaObject | boolean | Type | JsonSchema;
16
25
  items?: JsonSchemaObject | boolean | Type | JsonSchema | (JsonSchemaObject | Type | JsonSchema)[];
17
26
  pattern?: string | RegExp;
18
27
  }
28
+ /**
29
+ * Union type representing any valid JSON schema representation.
30
+ *
31
+ * This type accepts various schema formats including standard JSON Schema objects,
32
+ * Ts.ED JsonSchema instances, lazy references, TypeScript classes, and label objects.
33
+ * It provides maximum flexibility for schema definition across the framework.
34
+ *
35
+ * @typeParam T - The TypeScript type this schema represents
36
+ *
37
+ * @public
38
+ */
19
39
  export type AnyJsonSchema<T = any> = JsonSchemaObject | JSONSchema7 | JsonSchema<T> | JsonLazyRef | {
20
40
  label?: string;
21
41
  } | Type;
42
+ /**
43
+ * Core class representing a JSON Schema with TypeScript type integration.
44
+ *
45
+ * JsonSchema is the central class in Ts.ED's schema system, providing a Map-based
46
+ * interface for building and manipulating JSON Schema definitions. It extends the
47
+ * standard JSON Schema 7 specification with Ts.ED-specific features including:
48
+ *
49
+ * - TypeScript class and type integration
50
+ * - Property aliasing and naming strategies
51
+ * - Group-based conditional schemas
52
+ * - Discriminator support for polymorphic types
53
+ * - Generic type parameter handling
54
+ * - Schema composition (oneOf, allOf, anyOf)
55
+ * - Hook-based transformation pipeline
56
+ * - Vendor extension support
57
+ *
58
+ * ### Usage
59
+ *
60
+ * ```typescript
61
+ * // Create a basic schema
62
+ * const schema = new JsonSchema({
63
+ * type: "string",
64
+ * minLength: 1,
65
+ * maxLength: 100
66
+ * });
67
+ *
68
+ * // Create schema from TypeScript class
69
+ * class User {
70
+ * name: string;
71
+ * email: string;
72
+ * }
73
+ *
74
+ * const userSchema = JsonSchema.from(User);
75
+ *
76
+ * // Generate JSON Schema output
77
+ * const jsonSchema = userSchema.toJSON();
78
+ * ```
79
+ *
80
+ * ### Key Features
81
+ *
82
+ * - **Type Safety**: Generic type parameter `T` represents the TypeScript type
83
+ * - **Composition**: Support for allOf, oneOf, anyOf schema composition
84
+ * - **Validation**: Full JSON Schema validation keyword support
85
+ * - **Transformation**: Hook system for custom schema transformations
86
+ * - **Groups**: Conditional property inclusion based on groups
87
+ * - **Generics**: Support for generic type parameters in classes
88
+ *
89
+ * @typeParam T - The TypeScript type this schema represents
90
+ *
91
+ * @public
92
+ */
22
93
  export declare class JsonSchema<T = JSONSchema7Type> extends Map<string, any> {
23
94
  #private;
24
95
  readonly $kind: string;
@@ -30,81 +101,413 @@ export declare class JsonSchema<T = JSONSchema7Type> extends Map<string, any> {
30
101
  isDiscriminatorKey: boolean;
31
102
  isDiscriminator: boolean;
32
103
  constructor(obj?: Partial<JSONSchema7> | JsonSchema | Record<string, unknown>);
104
+ /**
105
+ * Get the alias map for property name aliases.
106
+ *
107
+ * The alias map allows bidirectional property name mapping, useful for
108
+ * serialization/deserialization with different naming conventions.
109
+ *
110
+ * @returns The alias map containing property-to-alias and alias-to-property mappings
111
+ */
33
112
  get alias(): AliasMap;
113
+ /**
114
+ * Check if this schema represents a TypeScript class (not a primitive or collection).
115
+ *
116
+ * @returns `true` if the schema represents a class, `false` otherwise
117
+ */
34
118
  get isClass(): boolean;
35
119
  /**
36
- * The current schema is a collection
120
+ * Check if this schema represents a collection (array, Set, Map, etc.).
121
+ *
122
+ * Collections have an associated item schema that defines the type of elements
123
+ * they contain.
124
+ *
125
+ * @returns `true` if the schema is a collection, `false` otherwise
37
126
  */
38
127
  get isCollection(): boolean;
39
128
  /**
40
- * The current schema is a reference to another schema
41
- * to link property/param to a class schema (if the reference exists).
129
+ * Check if this is a local schema reference.
130
+ *
131
+ * A local schema acts as a reference to link a property or parameter to a class schema.
132
+ * This is used for type resolution and avoids schema duplication.
133
+ *
134
+ * @returns `true` if this is a local schema reference, `false` otherwise
42
135
  */
43
136
  get isLocalSchema(): boolean;
44
137
  /**
45
- * Current schema is a generic
138
+ * Check if this schema represents a generic type.
139
+ *
140
+ * Generic schemas have a generic label vendor key and are used for parameterized types.
141
+ *
142
+ * @returns `true` if the schema is a generic type, `false` otherwise
46
143
  */
47
144
  get isGeneric(): boolean;
145
+ /**
146
+ * Get the ancestor schema that defines a discriminator.
147
+ *
148
+ * Searches through the class hierarchy to find a parent class with a discriminator
149
+ * configuration. This is used for polymorphic type resolution.
150
+ *
151
+ * @returns The ancestor schema with discriminator, or undefined if none found
152
+ */
48
153
  get discriminatorAncestor(): any;
49
154
  /**
50
- * Return the itemSchema computed type.
51
- * If the type is a function used for a recursive model,
52
- * the function will be called to get the right type.
155
+ * Get the computed TypeScript class or type for this schema.
156
+ *
157
+ * For local schemas, returns the item schema's target.
158
+ * For recursive models using functions, resolves the function to get the actual type.
159
+ *
160
+ * @returns The TypeScript class or type this schema represents
53
161
  */
54
162
  get class(): Type<any>;
55
163
  /**
56
- * Return the itemSchema computed type.
164
+ * Get the TypeScript class for collection items.
165
+ *
166
+ * For collection schemas, returns the type of elements in the collection.
167
+ * For non-collection schemas, returns the schema's own class.
168
+ *
169
+ * @returns The item class for collections, or the schema's class otherwise
57
170
  */
58
171
  get collectionClass(): Type<any>;
172
+ /**
173
+ * Check if this schema can use a $ref reference.
174
+ *
175
+ * Schemas with labels can be referenced by $ref to avoid duplication
176
+ * in generated OpenAPI specifications.
177
+ *
178
+ * @returns `true` if the schema can be referenced via $ref, `false` otherwise
179
+ */
59
180
  get canRef(): boolean;
181
+ /**
182
+ * Check if this schema allows null values.
183
+ *
184
+ * @returns `true` if the schema is nullable, `false` otherwise
185
+ */
60
186
  get isNullable(): boolean;
187
+ /**
188
+ * Check if this property is read-only.
189
+ *
190
+ * Read-only properties are included in responses but not accepted in requests.
191
+ *
192
+ * @returns `true` if the property is read-only, `false` otherwise
193
+ */
61
194
  get isReadOnly(): any;
195
+ /**
196
+ * Check if this property is write-only.
197
+ *
198
+ * Write-only properties are accepted in requests but not included in responses.
199
+ * Useful for sensitive data like passwords.
200
+ *
201
+ * @returns `true` if the property is write-only, `false` otherwise
202
+ */
62
203
  get isWriteOnly(): any;
204
+ /**
205
+ * Check if this schema has a discriminator configuration.
206
+ *
207
+ * Discriminators enable polymorphic type resolution based on a property value.
208
+ *
209
+ * @returns `true` if a discriminator is configured, `false` otherwise
210
+ */
63
211
  get hasDiscriminator(): boolean;
212
+ /**
213
+ * Create a JsonSchema from various input types.
214
+ *
215
+ * This factory method intelligently converts different input types into JsonSchema instances:
216
+ * - Existing JsonSchema: returned as-is
217
+ * - TypeScript classes: retrieves the schema from JsonEntityStore
218
+ * - Primitive classes (String, Number, etc.) and Date: creates type schema
219
+ * - Plain objects: creates schema from JSON Schema definition
220
+ *
221
+ * ### Usage
222
+ *
223
+ * ```typescript
224
+ * // From a class
225
+ * const schema1 = JsonSchema.from(User);
226
+ *
227
+ * // From a primitive
228
+ * const schema2 = JsonSchema.from(String);
229
+ *
230
+ * // From a schema object
231
+ * const schema3 = JsonSchema.from({type: "string", minLength: 1});
232
+ *
233
+ * // From existing schema (no-op)
234
+ * const schema4 = JsonSchema.from(schema1);
235
+ * ```
236
+ *
237
+ * @param item - The input to convert to a JsonSchema
238
+ * @returns A JsonSchema instance representing the input
239
+ */
64
240
  static from(item: Partial<JsonSchemaObject> | Type<any> | JsonSchema | undefined): JsonSchema<JSONSchema7Type>;
65
241
  /**
66
- * Check if the schema as key, #key or x-key
67
- * @param key
242
+ * Check if the schema has a property.
243
+ *
244
+ * Checks multiple locations in order:
245
+ * 1. Standard Map keys
246
+ * 2. Internal keys (prefixed with #)
247
+ * 3. Vendor extension keys
248
+ *
249
+ * @param key - The property key to check
250
+ * @returns `true` if the property exists, `false` otherwise
68
251
  */
69
252
  has(key: string): boolean;
70
253
  /**
71
- * Get the value of the schema by key, #key or x-key.
72
- * @param key
73
- * @param defaultValue
254
+ * Get a property value from the schema.
255
+ *
256
+ * Retrieves values from multiple locations in order:
257
+ * 1. Vendor extension keys
258
+ * 2. Standard Map keys
259
+ * 3. Internal keys (prefixed with #)
260
+ * 4. Default value if not found
261
+ *
262
+ * ### Usage
263
+ *
264
+ * ```typescript
265
+ * const minLength = schema.get("minLength", 0);
266
+ * const customKey = schema.get("x-custom");
267
+ * ```
268
+ *
269
+ * @param key - The property key to retrieve
270
+ * @param defaultValue - Optional default value if key not found
271
+ * @returns The property value or default value
74
272
  */
75
273
  get<T = any>(key: string, defaultValue: T): T;
76
274
  get<T = any>(key: string, defaultValue?: T): T | undefined;
275
+ /**
276
+ * Enable group forwarding to nested properties.
277
+ *
278
+ * When enabled, groups specified at the parent level are forwarded to nested
279
+ * object properties, allowing hierarchical group filtering.
280
+ *
281
+ * @param bool - Whether to enable group forwarding (default: true)
282
+ * @returns This schema instance for method chaining
283
+ */
77
284
  forwardGroups(bool?: boolean): this;
285
+ /**
286
+ * Assign groups to this property or schema.
287
+ *
288
+ * Groups enable conditional inclusion of properties based on serialization context.
289
+ * For example, you might have "admin" and "public" groups to control visibility.
290
+ *
291
+ * ### Usage
292
+ *
293
+ * ```typescript
294
+ * schema.groups(["admin", "internal"]);
295
+ * ```
296
+ *
297
+ * @param groups - Array of group names this property belongs to
298
+ * @param isProperty - Whether this is a property schema (enables group matching hooks)
299
+ * @returns This schema instance for method chaining
300
+ */
78
301
  groups(groups?: string[], isProperty?: boolean): this;
302
+ /**
303
+ * Set a custom name suffix for group-specific schema variations.
304
+ *
305
+ * This is used to generate unique schema names when the same model is used
306
+ * with different groups, avoiding conflicts in OpenAPI components.
307
+ *
308
+ * @param groupsName - The groups name suffix
309
+ * @returns This schema instance for method chaining
310
+ */
79
311
  groupsName(groupsName?: string): this;
312
+ /**
313
+ * Specify which groups are allowed access to this schema.
314
+ *
315
+ * @param groups - Array of group names allowed to access this schema
316
+ * @returns This schema instance for method chaining
317
+ */
80
318
  allowedGroups(groups?: string[]): this;
81
319
  /**
82
- * Assign the Generic Labels used over a class or a schema.
83
- * @param genericLabels
320
+ * Assign generic type parameter labels to a class or schema.
321
+ *
322
+ * Used for classes with generic type parameters (e.g., `Paginated<T>`)
323
+ * to track the parameter names for proper schema generation.
324
+ *
325
+ * ### Usage
326
+ *
327
+ * ```typescript
328
+ * schema.genericLabels(["T", "U"]);
329
+ * ```
330
+ *
331
+ * @param genericLabels - Array of generic type parameter names
332
+ * @returns This schema instance for method chaining
84
333
  */
85
334
  genericLabels(genericLabels: string[]): this;
335
+ /**
336
+ * Assign a single generic type label to this schema.
337
+ *
338
+ * Marks this schema as representing a generic type parameter.
339
+ *
340
+ * @param genericLabel - The generic type parameter name
341
+ * @returns This schema instance for method chaining
342
+ */
86
343
  genericLabel(genericLabel: string): this;
87
344
  /**
88
- * Assign the types of the generics that must be used for the property
89
- * @param generics
345
+ * Specify the concrete types for generic parameters.
346
+ *
347
+ * When using a generic class, this method assigns the actual types that should
348
+ * replace the generic parameters for this specific instance.
349
+ *
350
+ * ### Usage
351
+ *
352
+ * ```typescript
353
+ * // For Paginated<User>
354
+ * schema.genericOf([User]);
355
+ * ```
356
+ *
357
+ * @param generics - Arrays of generic type values to apply
358
+ * @returns This schema instance for method chaining
90
359
  */
91
360
  genericOf(...generics: GenericValue[][]): this;
361
+ /**
362
+ * Mark this schema as nullable or non-nullable.
363
+ *
364
+ * Nullable schemas can accept `null` values in addition to their base type.
365
+ * The type parameter is updated to reflect the nullability.
366
+ *
367
+ * ### Usage
368
+ *
369
+ * ```typescript
370
+ * // Make nullable
371
+ * schema.nullable(); // or schema.nullable(true)
372
+ *
373
+ * // Make non-nullable
374
+ * schema.nullable(false);
375
+ * ```
376
+ *
377
+ * @param value - Whether the schema is nullable (default: true)
378
+ * @returns This schema instance with updated type
379
+ */
92
380
  nullable(): JsonSchema<T | null>;
93
381
  nullable(value: true): JsonSchema<T | null>;
94
382
  nullable(value: false): JsonSchema<Exclude<T, null>>;
383
+ /**
384
+ * Get or create the item schema for collections.
385
+ *
386
+ * For array/collection types, this defines the schema for individual items.
387
+ * If the schema already has an item schema, it returns the existing one;
388
+ * otherwise, it creates a new one from the provided definition.
389
+ *
390
+ * ### Usage
391
+ *
392
+ * ```typescript
393
+ * // Define array items
394
+ * const arraySchema = new JsonSchema({type: "array"});
395
+ * arraySchema.itemSchema({type: "string", minLength: 1});
396
+ *
397
+ * // For class-based items
398
+ * arraySchema.itemSchema(User);
399
+ * ```
400
+ *
401
+ * @param obj - Schema definition for items
402
+ * @returns The item schema instance
403
+ */
95
404
  itemSchema(obj?: AnyJsonSchema): JsonSchema<JSONSchema7Type>;
405
+ /**
406
+ * Get the alias for a property name.
407
+ *
408
+ * @param property - The property name to look up
409
+ * @returns The alias for the property, or undefined if none exists
410
+ */
96
411
  getAliasOf(property: AliasType): AliasType | undefined;
412
+ /**
413
+ * Add a bidirectional alias mapping between property names.
414
+ *
415
+ * Aliases allow properties to be accessed by alternative names, useful for
416
+ * supporting different naming conventions (camelCase vs snake_case, etc.).
417
+ *
418
+ * ### Usage
419
+ *
420
+ * ```typescript
421
+ * schema.addAlias("userId", "user_id");
422
+ * // Both "userId" and "user_id" now map to each other
423
+ * ```
424
+ *
425
+ * @param property - The original property name
426
+ * @param alias - The alias name
427
+ * @returns This schema instance for method chaining
428
+ */
97
429
  addAlias(property: AliasType, alias: AliasType): this;
430
+ /**
431
+ * Remove an alias mapping for a property.
432
+ *
433
+ * @param property - The property name to remove aliases for
434
+ * @returns This schema instance for method chaining
435
+ */
98
436
  removeAlias(property: AliasType): this;
437
+ /**
438
+ * Set the `$id` keyword for this schema.
439
+ *
440
+ * The `$id` keyword is used to identify the schema and establish a base URI
441
+ * for resolving relative references.
442
+ *
443
+ * @param $id - The schema identifier URI
444
+ * @returns This schema instance for method chaining
445
+ */
99
446
  $id($id: string): this;
447
+ /**
448
+ * Set a `$ref` reference to another schema.
449
+ *
450
+ * The `$ref` keyword creates a reference to a schema defined elsewhere,
451
+ * enabling schema reuse and avoiding duplication.
452
+ *
453
+ * @param $ref - The reference URI (e.g., "#/components/schemas/User")
454
+ * @returns This schema instance for method chaining
455
+ */
100
456
  $ref($ref: string): this;
457
+ /**
458
+ * Set the JSON Schema version.
459
+ *
460
+ * @param $schema - The JSON Schema version URI
461
+ * @returns This schema instance for method chaining
462
+ */
101
463
  $schema($schema: JSONSchema7Version): this;
102
464
  /**
103
- * Create a ref and use name to sharing schema
104
- * @param name
465
+ * Assign a label to enable schema referencing.
466
+ *
467
+ * Labeled schemas can be referenced using `$ref` in OpenAPI specifications,
468
+ * reducing duplication by sharing schema definitions across endpoints.
469
+ *
470
+ * ### Usage
471
+ *
472
+ * ```typescript
473
+ * schema.label("User");
474
+ * // Can now be referenced as #/components/schemas/User
475
+ * ```
476
+ *
477
+ * @param name - The label name for the schema
478
+ * @returns This schema instance for method chaining
105
479
  */
106
480
  label(name: string): this;
481
+ /**
482
+ * Set the name of this schema.
483
+ *
484
+ * Unlike `label()`, this sets the name without enabling referencing.
485
+ *
486
+ * @param name - The schema name
487
+ * @returns This schema instance for method chaining
488
+ */
107
489
  name(name: string): this;
490
+ /**
491
+ * Mark this property as ignored during serialization.
492
+ *
493
+ * Ignored properties are excluded from generated schemas and serialization.
494
+ * Can be a boolean or a callback function for conditional ignoring.
495
+ *
496
+ * ### Usage
497
+ *
498
+ * ```typescript
499
+ * // Always ignore
500
+ * schema.ignore(true);
501
+ *
502
+ * // Conditionally ignore based on context
503
+ * schema.ignore((value, ctx) => {
504
+ * return ctx.groups?.includes("public");
505
+ * });
506
+ * ```
507
+ *
508
+ * @param cb - Boolean flag or callback function to determine if property should be ignored
509
+ * @returns This schema instance for method chaining
510
+ */
108
511
  ignore(cb: boolean | IgnoreCallback): this;
109
512
  /**
110
513
  * This keyword can be used to supply a default JSON value associated with a particular schema.
@@ -1,3 +1,29 @@
1
+ /**
2
+ * Specification types supported by Ts.ED's schema system.
3
+ *
4
+ * This enum defines the different API specification formats that can be generated
5
+ * from Ts.ED schemas. Each type affects how schemas are serialized and which
6
+ * features are available.
7
+ *
8
+ * ### Specification Types
9
+ *
10
+ * - **JSON**: Pure JSON Schema (no OpenAPI-specific features)
11
+ * - **SWAGGER**: Swagger 2.0 / OpenAPI 2.0 specification
12
+ * - **OPENAPI**: OpenAPI 3.x specification (recommended)
13
+ * - **ASYNCAPI**: AsyncAPI 2.x specification (for async/event-driven APIs)
14
+ *
15
+ * ### Usage
16
+ *
17
+ * ```typescript
18
+ * import {SpecTypes} from "@tsed/schema";
19
+ *
20
+ * const schema = getJsonSchema(MyModel, {
21
+ * specType: SpecTypes.OPENAPI
22
+ * });
23
+ * ```
24
+ *
25
+ * @public
26
+ */
1
27
  export declare enum SpecTypes {
2
28
  JSON = "jsonschema",
3
29
  SWAGGER = "swagger2",
@@ -1,7 +1,97 @@
1
1
  import type { JsonSchema } from "./JsonSchema.js";
2
+ /**
3
+ * Extracts the inferred TypeScript type from a JsonSchema.
4
+ *
5
+ * This utility type enables type-safe schema usage by extracting the type parameter
6
+ * from JsonSchema instances.
7
+ *
8
+ * ### Usage
9
+ *
10
+ * ```typescript
11
+ * const userSchema = JsonSchema.from({ type: "object" });
12
+ * type User = Infer<typeof userSchema>; // Extracts the type
13
+ * ```
14
+ *
15
+ * @typeParam S - The JsonSchema to extract the type from
16
+ *
17
+ * @public
18
+ */
2
19
  export type Infer<S> = S extends JsonSchema<infer T> ? T : never;
20
+ /**
21
+ * Maps an object of JsonSchema properties to a concrete TypeScript type.
22
+ *
23
+ * Converts a record of JsonSchema properties into a TypeScript type where each
24
+ * property has the inferred type from its corresponding schema.
25
+ *
26
+ * ### Usage
27
+ *
28
+ * ```typescript
29
+ * const properties = {
30
+ * name: string(),
31
+ * age: number(),
32
+ * email: string().format("email")
33
+ * };
34
+ *
35
+ * type Shape = PropsToShape<typeof properties>;
36
+ * // Result: { name: string; age: number; email: string }
37
+ * ```
38
+ *
39
+ * @typeParam P - Record of property names to JsonSchema instances
40
+ *
41
+ * @public
42
+ */
3
43
  export type PropsToShape<P extends Record<string, JsonSchema<any>>> = {
4
44
  [K in keyof P]: Infer<P[K]>;
5
45
  };
46
+ /**
47
+ * Maps common JavaScript constructors to their corresponding TypeScript types.
48
+ *
49
+ * This utility type converts constructor functions (String, Number, Date, etc.) into
50
+ * their corresponding runtime types, enabling better type inference when creating
51
+ * schemas programmatically.
52
+ *
53
+ * ### Type Mappings
54
+ *
55
+ * - `StringConstructor` → `string`
56
+ * - `NumberConstructor` → `number`
57
+ * - `BooleanConstructor` → `boolean`
58
+ * - `DateConstructor` → `Date`
59
+ * - `ArrayConstructor` → `any[]`
60
+ * - `MapConstructor` → `Record<string, any>`
61
+ * - `SetConstructor` → `Set<any>`
62
+ * - `ObjectConstructor` → `Record<string, any>`
63
+ * - Custom classes → `InstanceType<C>`
64
+ *
65
+ * ### Usage
66
+ *
67
+ * ```typescript
68
+ * type StringType = CtorToType<StringConstructor>; // string
69
+ * type DateType = CtorToType<DateConstructor>; // Date
70
+ * type CustomType = CtorToType<typeof MyClass>; // MyClass
71
+ * ```
72
+ *
73
+ * @typeParam C - The constructor function to map
74
+ *
75
+ * @public
76
+ */
6
77
  export type CtorToType<C> = C extends StringConstructor ? string : C extends NumberConstructor ? number : C extends BooleanConstructor ? boolean : C extends DateConstructor ? Date : C extends ArrayConstructor ? any[] : C extends MapConstructor ? Record<string, any> : C extends SetConstructor ? Set<any> : C extends ObjectConstructor ? Record<string, any> : C extends abstract new (...args: any) => any ? InstanceType<C> : any;
78
+ /**
79
+ * Converts a union type to an intersection type.
80
+ *
81
+ * This advanced TypeScript utility transforms a union of types (A | B | C) into
82
+ * an intersection of types (A & B & C), which is useful for schema composition
83
+ * and merging operations.
84
+ *
85
+ * ### Usage
86
+ *
87
+ * ```typescript
88
+ * type Union = { a: string } | { b: number };
89
+ * type Intersection = UnionToIntersection<Union>;
90
+ * // Result: { a: string } & { b: number }
91
+ * ```
92
+ *
93
+ * @typeParam U - The union type to convert
94
+ *
95
+ * @public
96
+ */
7
97
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
@@ -1,8 +1,44 @@
1
1
  /**
2
- * Declare a new boolean model.
2
+ * Create a boolean schema programmatically.
3
3
  *
4
- * See @@JsonSchema@@ to discover available methods.
4
+ * This function provides a fluent API for building boolean schemas without decorators.
5
+ * It returns a JsonSchema instance configured for boolean type, which can be further
6
+ * customized with descriptions, defaults, and other JSON Schema properties.
5
7
  *
6
- * @schemaFunctional
8
+ * ### Usage
9
+ *
10
+ * ```typescript
11
+ * import {boolean} from "@tsed/schema";
12
+ *
13
+ * // Basic boolean schema
14
+ * const activeSchema = boolean();
15
+ *
16
+ * // Boolean with description and default
17
+ * const isVerifiedSchema = boolean()
18
+ * .description("Whether the user is verified")
19
+ * .default(false);
20
+ *
21
+ * // Required boolean
22
+ * const termsAcceptedSchema = boolean()
23
+ * .description("User accepted terms and conditions")
24
+ * .required();
25
+ *
26
+ * // Nullable boolean
27
+ * const optionalFlagSchema = boolean()
28
+ * .nullable()
29
+ * .description("Optional feature flag");
30
+ * ```
31
+ *
32
+ * ### Available Methods
33
+ *
34
+ * The returned JsonSchema provides many chainable methods:
35
+ * - `description(text)` - Add description
36
+ * - `default(value)` - Set default value (true or false)
37
+ * - `nullable()` - Allow null values
38
+ * - `const(value)` - Restrict to a single value
39
+ *
40
+ * @returns A new JsonSchema configured as a boolean type
41
+ *
42
+ * @public
7
43
  */
8
44
  export declare function boolean(): import("../index.js").JsonSchema<boolean>;