@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
@@ -2,47 +2,84 @@ import { withErrorMsg } from "../../utils/withErrorMsg.js";
2
2
  import { Allow } from "./allow.js";
3
3
  import { Optional } from "./optional.js";
4
4
  /**
5
- * Add required annotation on Property or Parameter.
5
+ * Mark a property or parameter as required.
6
6
  *
7
- * The @@Required@@ decorator can be used on two cases.
7
+ * The `@Required()` decorator enforces that a property must have a value during
8
+ * validation. It works on both model properties and method parameters, and triggers
9
+ * validation errors when values are `null`, `undefined`, or empty strings.
8
10
  *
9
- * To decorate a parameters:
11
+ * ### Usage on Properties
10
12
  *
11
13
  * ```typescript
12
- * @Post("/")
13
- * async method(@Required() @BodyParams("field") field: string) {}
14
+ * class User {
15
+ * @Required()
16
+ * @Property()
17
+ * email: string;
18
+ *
19
+ * @Required()
20
+ * @Property()
21
+ * name: string;
22
+ * }
14
23
  * ```
15
24
  *
16
- * To decorate a model:
25
+ * ### Usage on Parameters
26
+ *
27
+ * ```typescript
28
+ * @Controller("/users")
29
+ * class UserController {
30
+ * @Post("/")
31
+ * async create(@Required() @BodyParams() user: User) {
32
+ * // user is required in request body
33
+ * }
34
+ *
35
+ * @Get("/:id")
36
+ * async get(@Required() @PathParams("id") id: string) {
37
+ * // id is required in path
38
+ * }
39
+ * }
40
+ * ```
41
+ *
42
+ * ### Validation Behavior
43
+ *
44
+ * By default, `@Required()` rejects:
45
+ * - `null` values
46
+ * - `undefined` values
47
+ * - Empty strings (`""`)
48
+ *
49
+ * ### Allowing Specific Values
50
+ *
51
+ * Use `@Allow()` to permit specific values that would normally be rejected:
17
52
  *
18
53
  * ```typescript
19
54
  * class Model {
55
+ * // Allow empty string but still mark as required
20
56
  * @Required()
21
- * field: string;
57
+ * @Allow("")
58
+ * optionalText: string;
59
+ *
60
+ * // Allow null
61
+ * @Required()
62
+ * @Allow(null)
63
+ * nullableField: string | null;
22
64
  * }
23
65
  * ```
24
66
  *
25
- * ::: tip
26
- * Required will throw a BadRequest when the given value is `null`, an empty string or `undefined`.
27
- * :::
67
+ * ### Making Optional
28
68
  *
29
- * ### Allow values
30
- *
31
- * In some case, you didn't want trigger a BadRequest when the value is an empty string for example.
32
- * The decorator `@Allow()`, allow you to configure a value list for which there will be no exception.
69
+ * To explicitly mark a property as optional:
33
70
  *
34
71
  * ```typescript
35
72
  * class Model {
36
- * @Allow("") // add automatically required flag
37
- * field: string;
73
+ * @Required(false) // or use @Optional()
74
+ * optionalField: string;
38
75
  * }
39
76
  * ```
40
77
  *
78
+ * @param required - Whether the property/parameter is required (default: true)
79
+ * @param allowedRequiredValues - Values to allow even when marked as required
80
+ *
41
81
  * @decorator
42
- * @validation
43
- * @swagger
44
- * @schema
45
- * @input
82
+ * @public
46
83
  */
47
84
  export const Required = withErrorMsg("required", (required = true, ...allowedRequiredValues) => {
48
85
  return required ? Allow(...allowedRequiredValues) : Optional();
@@ -1,13 +1,125 @@
1
1
  import { JsonEntityFn } from "./jsonEntityFn.js";
2
2
  /**
3
- * Set the property as WriteOnly.
3
+ * Marks a property as write-only, indicating it should not be included in responses.
4
+ *
5
+ * The `@WriteOnly()` decorator sets the `writeOnly` flag in the JSON Schema, which signals
6
+ * that this property should only appear in request payloads and be excluded from response
7
+ * data. This is commonly used for sensitive data like passwords that should be accepted
8
+ * as input but never returned to clients.
9
+ *
10
+ * ### Basic Usage - Passwords
11
+ *
12
+ * ```typescript
13
+ * class UserModel {
14
+ * @Property()
15
+ * username: string;
16
+ * // Readable and writable
17
+ *
18
+ * @WriteOnly()
19
+ * password: string;
20
+ * // Can be sent in requests but never returned in responses
21
+ * }
22
+ * ```
23
+ *
24
+ * ### Registration/Update Models
25
+ *
26
+ * ```typescript
27
+ * class UserRegistration {
28
+ * @Property()
29
+ * email: string;
30
+ *
31
+ * @WriteOnly()
32
+ * @MinLength(8)
33
+ * password: string;
34
+ *
35
+ * @WriteOnly()
36
+ * passwordConfirmation: string;
37
+ * // Only needed for validation, never stored or returned
38
+ * }
39
+ * ```
40
+ *
41
+ * ### Sensitive Configuration
42
+ *
43
+ * ```typescript
44
+ * class ApiKeyConfig {
45
+ * @Property()
46
+ * name: string;
47
+ *
48
+ * @WriteOnly()
49
+ * apiKey: string;
50
+ * // Accept key in requests, but don't expose it in responses
51
+ *
52
+ * @ReadOnly()
53
+ * createdAt: Date;
54
+ * // Only in responses
55
+ * }
56
+ * ```
57
+ *
58
+ * ### Toggle Write-Only
59
+ *
60
+ * ```typescript
61
+ * class SecureModel {
62
+ * @WriteOnly(true)
63
+ * secret: string;
64
+ * // Write-only
65
+ *
66
+ * @WriteOnly(false)
67
+ * publicField: string;
68
+ * // Explicitly not write-only (default behavior)
69
+ * }
70
+ * ```
71
+ *
72
+ * ### OpenAPI Behavior
73
+ *
74
+ * In OpenAPI/Swagger documentation:
75
+ * - Write-only properties appear in **request** schemas
76
+ * - Write-only properties are **excluded** from **response** schemas
77
+ * - Helps document sensitive fields that shouldn't be returned
78
+ *
79
+ * ### vs ReadOnly
80
+ *
81
+ * - `@WriteOnly()`: Property can be written but not read (requests only)
82
+ * - `@ReadOnly()`: Property can be read but not written (responses only)
83
+ * - Neither: Property can be both read and written
84
+ *
85
+ * ### Common Use Cases
86
+ *
87
+ * - **Passwords**: Authentication credentials that should never be exposed
88
+ * - **Secret Keys**: API keys, tokens, or other sensitive credentials
89
+ * - **Confirmation Fields**: Password confirmation, email confirmation
90
+ * - **Temporary Inputs**: Fields used only for processing, not storage
91
+ * - **Security Tokens**: CSRF tokens or one-time codes
92
+ *
93
+ * ### Security Best Practices
94
+ *
95
+ * ```typescript
96
+ * class ChangePassword {
97
+ * @WriteOnly()
98
+ * @MinLength(8)
99
+ * currentPassword: string;
100
+ *
101
+ * @WriteOnly()
102
+ * @MinLength(8)
103
+ * newPassword: string;
104
+ *
105
+ * @WriteOnly()
106
+ * newPasswordConfirmation: string;
107
+ * // All password fields are write-only
108
+ * }
109
+ * ```
110
+ *
111
+ * ### Important Notes
112
+ *
113
+ * - `@WriteOnly()` is a schema hint for documentation and client validation
114
+ * - Server-side code must still explicitly exclude these fields from responses
115
+ * - Use serialization groups or DTOs to ensure write-only fields aren't leaked
116
+ * - Always hash/encrypt sensitive data before storage
117
+ *
118
+ * @param writeOnly - Whether the property is write-only (default: true)
4
119
  *
5
- * @returns {Function}
6
120
  * @decorator
7
121
  * @validation
8
- * @property
9
- * @parameter
10
- * @schema
122
+ * @public
11
123
  */
12
124
  export function WriteOnly(writeOnly = true) {
13
125
  return JsonEntityFn((store) => {
@@ -3,6 +3,81 @@ import { DecoratorTypes } from "@tsed/core";
3
3
  import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
4
4
  import { JsonEntityStore } from "./JsonEntityStore.js";
5
5
  import { JsonSchema } from "./JsonSchema.js";
6
+ /**
7
+ * Store for class-level metadata and schema information.
8
+ *
9
+ * JsonClassStore manages metadata for classes decorated with schema decorators like
10
+ * `@Model()`, `@Generics()`, `@DiscriminatorKey()`, etc. It serves as the root container
11
+ * for all class-level schema information and coordinates child stores for properties
12
+ * and methods.
13
+ *
14
+ * ### Responsibilities
15
+ *
16
+ * - **Schema Generation**: Creates and maintains the JsonSchema for the class
17
+ * - **Children Coordination**: Manages child PropertyStore and MethodStore instances
18
+ * - **Route Configuration**: Stores base path for controller classes
19
+ * - **Inheritance**: Handles schema inheritance from parent classes
20
+ * - **OpenAPI Integration**: Generates component schemas for OpenAPI specifications
21
+ *
22
+ * ### Usage
23
+ *
24
+ * ```typescript
25
+ * // Get class store
26
+ * const classStore = JsonEntityStore.from(MyClass);
27
+ *
28
+ * // Access class schema
29
+ * const schema = classStore.schema;
30
+ *
31
+ * // Get all properties
32
+ * const properties = classStore.children;
33
+ *
34
+ * // Check if it's a controller with a path
35
+ * const path = classStore.path;
36
+ * ```
37
+ *
38
+ * ### Class Store Hierarchy
39
+ *
40
+ * The class store acts as the root of the store hierarchy:
41
+ * ```
42
+ * JsonClassStore (User class)
43
+ * ├─ JsonPropertyStore (name property)
44
+ * ├─ JsonPropertyStore (email property)
45
+ * └─ JsonMethodStore (validate method)
46
+ * ├─ JsonParameterStore (param 0)
47
+ * └─ JsonParameterStore (param 1)
48
+ * ```
49
+ *
50
+ * ### Schema Structure
51
+ *
52
+ * For a class like:
53
+ * ```typescript
54
+ * class User {
55
+ * @Property()
56
+ * name: string;
57
+ *
58
+ * @Property()
59
+ * email: string;
60
+ * }
61
+ * ```
62
+ *
63
+ * The class store generates:
64
+ * ```json
65
+ * {
66
+ * "type": "object",
67
+ * "properties": {
68
+ * "name": {"type": "string"},
69
+ * "email": {"type": "string"}
70
+ * }
71
+ * }
72
+ * ```
73
+ *
74
+ * ### Controller Path
75
+ *
76
+ * For controller classes decorated with `@Controller("/users")`, the store
77
+ * maintains the base path which is used for route generation.
78
+ *
79
+ * @public
80
+ */
6
81
  let JsonClassStore = class JsonClassStore extends JsonEntityStore {
7
82
  constructor() {
8
83
  super(...arguments);
@@ -1,4 +1,61 @@
1
1
  import { cleanObject } from "@tsed/core";
2
+ /**
3
+ * Manages discriminator mappings for polymorphic type resolution.
4
+ *
5
+ * A discriminator enables polymorphism in schemas by using a specific property
6
+ * value to determine which subtype schema to apply. This is essential for
7
+ * inheritance hierarchies and union types in OpenAPI specifications.
8
+ *
9
+ * ### Concept
10
+ *
11
+ * When a base class has multiple derived classes, the discriminator property
12
+ * (e.g., "type", "kind") indicates which concrete class an object represents.
13
+ *
14
+ * ### Usage
15
+ *
16
+ * ```typescript
17
+ * // Base class
18
+ * @DiscriminatorKey("type")
19
+ * abstract class Animal {
20
+ * type: string;
21
+ * }
22
+ *
23
+ * // Derived classes
24
+ * @DiscriminatorValue("dog")
25
+ * class Dog extends Animal {
26
+ * breed: string;
27
+ * }
28
+ *
29
+ * @DiscriminatorValue("cat")
30
+ * class Cat extends Animal {
31
+ * indoor: boolean;
32
+ * }
33
+ * ```
34
+ *
35
+ * ### OpenAPI Mapping
36
+ *
37
+ * Generates OpenAPI discriminator objects:
38
+ * ```json
39
+ * {
40
+ * "discriminator": {
41
+ * "propertyName": "type",
42
+ * "mapping": {
43
+ * "dog": "#/components/schemas/Dog",
44
+ * "cat": "#/components/schemas/Cat"
45
+ * }
46
+ * }
47
+ * }
48
+ * ```
49
+ *
50
+ * ### Key Features
51
+ *
52
+ * - **Type Mapping**: Maps discriminator values to TypeScript classes
53
+ * - **Bidirectional Lookup**: Find type by value or values by type
54
+ * - **Default Values**: Get the default discriminator value for a type
55
+ * - **Children Discovery**: List all derived types
56
+ *
57
+ * @public
58
+ */
2
59
  export class Discriminator {
3
60
  constructor({ base, propertyName, types, values } = {}) {
4
61
  this.values = new Map();
@@ -3,6 +3,52 @@ import { ancestorsOf, classOf, decoratorTypeOf, descriptorOf, isArrayOrArrayClas
3
3
  * @ignore
4
4
  */
5
5
  export const JsonEntitiesContainer = new Map();
6
+ /**
7
+ * Base class for storing metadata about decorated entities (classes, properties, methods, parameters).
8
+ *
9
+ * JsonEntityStore is the foundation of Ts.ED's metadata system, managing schema information
10
+ * and type metadata for decorated entities. It serves as the parent class for specialized
11
+ * stores (JsonClassStore, JsonPropertyStore, JsonMethodStore, JsonParameterStore).
12
+ *
13
+ * ### Entity Types
14
+ *
15
+ * Different decorator types create different store subclasses:
16
+ * - **Class decorators**: Create JsonClassStore instances
17
+ * - **Property decorators**: Create JsonPropertyStore instances
18
+ * - **Method decorators**: Create JsonMethodStore instances
19
+ * - **Parameter decorators**: Create JsonParameterStore instances
20
+ *
21
+ * ### Key Responsibilities
22
+ *
23
+ * - **Schema Management**: Each store maintains a JsonSchema for the decorated entity
24
+ * - **Type Resolution**: Resolves TypeScript types, including collections and generics
25
+ * - **Metadata Storage**: Stores decorator metadata using Ts.ED's Store system
26
+ * - **Inheritance**: Manages parent-child relationships between entities
27
+ *
28
+ * ### Usage
29
+ *
30
+ * Stores are typically accessed via static `from()` methods:
31
+ *
32
+ * ```typescript
33
+ * // Get store for a class
34
+ * const classStore = JsonEntityStore.from(MyClass);
35
+ *
36
+ * // Get store for a property
37
+ * const propStore = JsonEntityStore.from(MyClass, "propertyName");
38
+ *
39
+ * // Get store for a method parameter
40
+ * const paramStore = JsonEntityStore.from(MyClass, "methodName", 0);
41
+ * ```
42
+ *
43
+ * ### Architecture
44
+ *
45
+ * The store system creates a hierarchical structure:
46
+ * - ClassStore contains PropertyStore and MethodStore children
47
+ * - MethodStore contains ParameterStore children
48
+ * - Each store has an associated JsonSchema
49
+ *
50
+ * @public
51
+ */
6
52
  export class JsonEntityStore {
7
53
  constructor(options) {
8
54
  this.isStore = true;
@@ -1,3 +1,42 @@
1
+ /**
2
+ * Standard JSON Schema format types for string validation.
3
+ *
4
+ * These format types provide semantic validation for string values beyond basic
5
+ * pattern matching. They are part of the JSON Schema specification and widely
6
+ * supported by validation libraries.
7
+ *
8
+ * ### Date and Time Formats
9
+ * - **DATE_TIME**: RFC 3339 date-time (e.g., "2024-01-15T10:30:00Z")
10
+ * - **DATE**: RFC 3339 full-date (e.g., "2024-01-15")
11
+ * - **TIME**: RFC 3339 full-time (e.g., "10:30:00")
12
+ *
13
+ * ### Network Formats
14
+ * - **EMAIL**: Email address (RFC 5322)
15
+ * - **HOSTNAME**: Internet hostname (RFC 1123)
16
+ * - **IPV4**: IPv4 address
17
+ * - **IPV6**: IPv6 address
18
+ * - **URI**: Uniform Resource Identifier (RFC 3986)
19
+ * - **URL**: URL variant of URI
20
+ * - **URI_REF**: URI reference
21
+ * - **URI_TEMPLATE**: URI template (RFC 6570)
22
+ *
23
+ * ### Other Formats
24
+ * - **JSON_POINTER**: JSON Pointer (RFC 6901)
25
+ * - **RELATIVE_JSON_POINTER**: Relative JSON Pointer
26
+ * - **UUID**: Universally Unique Identifier (RFC 4122)
27
+ * - **REGEX**: Regular expression (ECMA-262)
28
+ *
29
+ * ### Usage
30
+ *
31
+ * ```typescript
32
+ * import {JsonFormatTypes} from "@tsed/schema";
33
+ *
34
+ * schema.format(JsonFormatTypes.EMAIL);
35
+ * schema.format(JsonFormatTypes.DATE_TIME);
36
+ * ```
37
+ *
38
+ * @public
39
+ */
1
40
  export var JsonFormatTypes;
2
41
  (function (JsonFormatTypes) {
3
42
  JsonFormatTypes["DATE_TIME"] = "date-time";
@@ -1,5 +1,38 @@
1
1
  import { nameOf } from "@tsed/core";
2
2
  import { getJsonEntityStore } from "../utils/getJsonEntityStore.js";
3
+ /**
4
+ * Lazy reference to a schema type for handling circular dependencies.
5
+ *
6
+ * JsonLazyRef provides a deferred reference mechanism for types that may not be
7
+ * available at decoration time due to circular dependencies or forward references.
8
+ * The actual type is resolved lazily when needed, avoiding initialization order issues.
9
+ *
10
+ * ### Usage
11
+ *
12
+ * ```typescript
13
+ * class User {
14
+ * @Property()
15
+ * name: string;
16
+ *
17
+ * // Circular reference - user has a manager who is also a user
18
+ * @Property()
19
+ * manager: User; // Internally uses lazy ref
20
+ * }
21
+ * ```
22
+ *
23
+ * ### Use Cases
24
+ *
25
+ * - **Circular Dependencies**: Classes that reference themselves or each other
26
+ * - **Forward References**: References to classes defined later in the file
27
+ * - **Conditional Imports**: Types that may not be available immediately
28
+ *
29
+ * ### How It Works
30
+ *
31
+ * The lazy ref wraps a function that returns the type, delaying type resolution
32
+ * until the schema is actually needed during schema generation.
33
+ *
34
+ * @public
35
+ */
3
36
  export class JsonLazyRef {
4
37
  constructor(getType) {
5
38
  this.getType = getType;
@@ -1,5 +1,37 @@
1
1
  import { isFunction } from "@tsed/core";
2
2
  import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
3
+ /**
4
+ * Base class for JSON document representations using a Map structure.
5
+ *
6
+ * JsonMap provides a Map-based foundation for storing and manipulating JSON-compatible
7
+ * data structures. It extends the native Map with additional features for assignment,
8
+ * serialization, and mapper integration.
9
+ *
10
+ * This class serves as the base for many Ts.ED schema classes including JsonOperation,
11
+ * JsonParameter, JsonResponse, and JsonRequestBody.
12
+ *
13
+ * ### Usage
14
+ *
15
+ * ```typescript
16
+ * class MyJsonDoc extends JsonMap<{name: string; value: number}> {
17
+ * // Custom methods
18
+ * }
19
+ *
20
+ * const doc = new MyJsonDoc({name: "test", value: 42});
21
+ * const json = doc.toJSON();
22
+ * ```
23
+ *
24
+ * ### Key Features
25
+ *
26
+ * - **Map Interface**: Full Map API support for key-value operations
27
+ * - **Fluent Assignment**: Assign multiple properties via object
28
+ * - **Serialization**: Convert to plain JSON via mapper system
29
+ * - **Type Safety**: Generic type parameter for stored values
30
+ *
31
+ * @typeParam T - The shape of the object this map represents
32
+ *
33
+ * @public
34
+ */
3
35
  export class JsonMap extends Map {
4
36
  constructor(obj = {}) {
5
37
  super();
@@ -1,6 +1,34 @@
1
1
  import { isArray, isClass } from "@tsed/core";
2
2
  import { JsonMap } from "./JsonMap.js";
3
3
  import { JsonSchema } from "./JsonSchema.js";
4
+ /**
5
+ * Represents a media type definition for HTTP request or response bodies.
6
+ *
7
+ * JsonMedia encapsulates the schema and examples for a specific media type
8
+ * (e.g., "application/json", "application/xml") in OpenAPI specifications.
9
+ * It provides methods to configure the schema and examples for the media type.
10
+ *
11
+ * ### Usage
12
+ *
13
+ * ```typescript
14
+ * const media = new JsonMedia();
15
+ * media.type(User);
16
+ * media.examples({
17
+ * user1: {
18
+ * value: {name: "John", email: "john@example.com"}
19
+ * }
20
+ * });
21
+ * ```
22
+ *
23
+ * ### Key Features
24
+ *
25
+ * - **Schema Definition**: Associated JSON schema for validation
26
+ * - **Examples**: Request/response examples for documentation
27
+ * - **Type Handling**: Automatic schema generation from TypeScript types
28
+ * - **Union Types**: Support for oneOf schemas with multiple types
29
+ *
30
+ * @public
31
+ */
4
32
  export class JsonMedia extends JsonMap {
5
33
  constructor(obj = {}) {
6
34
  super(obj);
@@ -5,6 +5,62 @@ import { isSuccessStatus } from "../utils/isSuccessStatus.js";
5
5
  import { JsonEntityStore } from "./JsonEntityStore.js";
6
6
  import { JsonOperation } from "./JsonOperation.js";
7
7
  import { JsonSchema } from "./JsonSchema.js";
8
+ /**
9
+ * Store for method metadata, operations, and parameter information.
10
+ *
11
+ * JsonMethodStore manages metadata for controller methods decorated with operation
12
+ * decorators like `@Get()`, `@Post()`, `@Returns()`, etc. It maintains the JsonOperation
13
+ * for OpenAPI generation and coordinates method parameters.
14
+ *
15
+ * ### Responsibilities
16
+ *
17
+ * - **Operation Management**: Maintains JsonOperation for OpenAPI spec generation
18
+ * - **Parameter Coordination**: Manages child JsonParameterStore instances
19
+ * - **Middleware Configuration**: Handles before/after/use middleware registration
20
+ * - **Response Configuration**: Manages return types and status codes
21
+ * - **Route Information**: Stores HTTP methods, paths, and route metadata
22
+ *
23
+ * ### Usage
24
+ *
25
+ * ```typescript
26
+ * // Get method store
27
+ * const methodStore = JsonEntityStore.from(MyController, "myMethod");
28
+ *
29
+ * // Access operation for OpenAPI
30
+ * const operation = methodStore.operation;
31
+ *
32
+ * // Get parameters
33
+ * const params = methodStore.parameters;
34
+ *
35
+ * // Check response type
36
+ * const returnType = methodStore.type;
37
+ * ```
38
+ *
39
+ * ### Operation Structure
40
+ *
41
+ * Each method store contains a JsonOperation that includes:
42
+ * - HTTP method and path information
43
+ * - Request parameters (path, query, body, headers)
44
+ * - Response definitions by status code
45
+ * - Security requirements
46
+ * - Tags and metadata
47
+ *
48
+ * ### Parameter Management
49
+ *
50
+ * The store maintains parameter metadata:
51
+ * - Parameters stored in `children` map by index
52
+ * - Accessible via `parameters` or `params` getters
53
+ * - Each parameter has its own JsonParameterStore
54
+ *
55
+ * ### Middleware Integration
56
+ *
57
+ * Supports three middleware phases:
58
+ * - **before**: Execute before the method
59
+ * - **use**: Execute as main middleware
60
+ * - **after**: Execute after the method
61
+ *
62
+ * @public
63
+ */
8
64
  let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
9
65
  constructor(options) {
10
66
  super({