typia 9.3.1 → 9.4.0

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.
@@ -1,10 +1,39 @@
1
1
  import type { OpenApi, OpenApiV3 } from "@samchon/openapi";
2
2
 
3
3
  /**
4
- * Collection of JSON schemas.
4
+ * Collection of JSON schemas with OpenAPI specification support.
5
+ *
6
+ * `IJsonSchemaCollection` represents a comprehensive collection of JSON schemas
7
+ * that can be generated from TypeScript types using the `typia.json.schemas()` function.
8
+ * This interface supports both OpenAPI v3.0 and v3.1 specifications, with the ability
9
+ * to automatically generate appropriate schema definitions based on the specified version.
10
+ *
11
+ * The collection includes:
12
+ * - Generated JSON schemas array containing schema definitions for the specified types
13
+ * - Reusable components that can be referenced across different schemas
14
+ * - Version-specific formatting that adheres to either OpenAPI v3.0 or v3.1 standards
15
+ *
16
+ * Key differences between versions:
17
+ * - OpenAPI v3.0: Uses {@link OpenApiV3.IJsonSchema} format with limited tuple support
18
+ * - OpenAPI v3.1: Uses {@link OpenApi.IJsonSchema} format with full JSON Schema Draft 2020-12 compatibility
19
+ *
20
+ * @template Version The OpenAPI specification version to target ("3.0" or "3.1").
21
+ * Defaults to "3.1" for enhanced JSON Schema compatibility.
22
+ * @template Types Array of original TypeScript types that were analyzed to generate
23
+ * the JSON schemas. This provides type safety and traceability
24
+ * back to the source TypeScript definitions.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Generate schemas for OpenAPI v3.1 (default)
29
+ * const schemas = typia.json.schemas<[User, Product]>();
30
+ * // Type: IJsonSchemaCollection<"3.1", [User, Product]>
31
+ *
32
+ * // Generate schemas for OpenAPI v3.0 (Swagger compatibility)
33
+ * const swaggerSchemas = typia.json.schemas<[User, Product], "3.0">();
34
+ * // Type: IJsonSchemaCollection<"3.0", [User, Product]>
35
+ * ```
5
36
  *
6
- * @template Version Version of the OpenAPI specification.
7
- * @template Types Original TypeScript types used in the JSON schemas.
8
37
  * @author Jeongho Nam - https://github.com/samchon
9
38
  */
10
39
  export type IJsonSchemaCollection<
@@ -13,17 +42,154 @@ export type IJsonSchemaCollection<
13
42
  > = Version extends "3.0"
14
43
  ? IJsonSchemaCollection.IV3_0<Types>
15
44
  : IJsonSchemaCollection.IV3_1<Types>;
45
+
16
46
  export namespace IJsonSchemaCollection {
47
+ /**
48
+ * JSON Schema collection formatted for OpenAPI v3.0 specification.
49
+ *
50
+ * This interface represents a collection of JSON schemas that comply with
51
+ * OpenAPI v3.0 standards, which are compatible with Swagger tools and
52
+ * legacy OpenAPI implementations. OpenAPI v3.0 has some limitations
53
+ * compared to v3.1, particularly around tuple types and pattern properties.
54
+ *
55
+ * Key characteristics of v3.0:
56
+ * - Cannot express tuple types natively (falls back to array representations)
57
+ * - Cannot express pattern properties in object schemas
58
+ * - Uses nullable property instead of union with null type
59
+ * - Limited JSON Schema Draft compatibility (based on Draft 4)
60
+ *
61
+ * @template Types Array of original TypeScript types used to generate the schemas.
62
+ * This provides compile-time type information about what types
63
+ * were analyzed during schema generation.
64
+ */
17
65
  export interface IV3_0<Types = unknown[]> {
66
+ /**
67
+ * OpenAPI specification version identifier.
68
+ *
69
+ * Always set to "3.0" to indicate this collection uses OpenAPI v3.0
70
+ * schema format and constraints.
71
+ */
18
72
  version: "3.0";
73
+
74
+ /**
75
+ * Array of generated JSON schemas.
76
+ *
77
+ * Contains the actual JSON schema definitions generated from the input TypeScript types.
78
+ * Each schema in this array corresponds to one of the types specified in the `Types`
79
+ * template parameter. The schemas follow OpenAPI v3.0 format and may contain
80
+ * references to components defined in the {@link components} property.
81
+ *
82
+ * Schema references typically use the format: `{ "$ref": "#/components/schemas/TypeName" }`
83
+ */
19
84
  schemas: OpenApiV3.IJsonSchema[];
85
+
86
+ /**
87
+ * Reusable schema components for OpenAPI v3.0.
88
+ *
89
+ * Contains reusable schema definitions, security schemes, and other components
90
+ * that can be referenced from the main schemas. This follows the OpenAPI v3.0
91
+ * components structure and enables schema reuse and modularity.
92
+ *
93
+ * Components include:
94
+ * - schemas: Named type definitions that can be referenced via $ref
95
+ * - securitySchemes: Authentication and authorization schemes
96
+ * - parameters: Reusable parameter definitions
97
+ * - requestBodies: Reusable request body definitions
98
+ * - responses: Reusable response definitions
99
+ * - headers: Reusable header definitions
100
+ * - examples: Reusable example definitions
101
+ */
20
102
  components: OpenApiV3.IComponents;
103
+
104
+ /**
105
+ * Type metadata for compile-time type tracking.
106
+ *
107
+ * This optional property stores the original TypeScript types that were
108
+ * used to generate the JSON schemas. It's primarily used for type safety
109
+ * and doesn't affect runtime behavior. The property is marked as optional
110
+ * and undefined to prevent it from appearing in serialized JSON output.
111
+ *
112
+ * This enables:
113
+ * - Compile-time type checking against the original types
114
+ * - IDE intellisense and autocompletion
115
+ * - Type-safe schema validation and usage
116
+ */
21
117
  __types?: Types | undefined;
22
118
  }
119
+
120
+ /**
121
+ * JSON Schema collection formatted for OpenAPI v3.1 specification.
122
+ *
123
+ * This interface represents a collection of JSON schemas that comply with
124
+ * OpenAPI v3.1 standards, which provide enhanced JSON Schema compatibility
125
+ * and support for modern JSON Schema features. OpenAPI v3.1 is based on
126
+ * JSON Schema Draft 2020-12 and offers significant improvements over v3.0.
127
+ *
128
+ * Key advantages of v3.1:
129
+ * - Full tuple type support with prefixItems
130
+ * - Pattern properties support for dynamic object keys
131
+ * - Proper null type handling via union types
132
+ * - Enhanced JSON Schema Draft 2020-12 compatibility
133
+ * - Better const, enum, and validation support
134
+ *
135
+ * @template Types Array of original TypeScript types used to generate the schemas.
136
+ * This provides compile-time type information about what types
137
+ * were analyzed during schema generation.
138
+ */
23
139
  export interface IV3_1<Types = unknown[]> {
140
+ /**
141
+ * OpenAPI specification version identifier.
142
+ *
143
+ * Always set to "3.1" to indicate this collection uses OpenAPI v3.1
144
+ * schema format with enhanced JSON Schema compatibility.
145
+ */
24
146
  version: "3.1";
147
+
148
+ /**
149
+ * Reusable schema components for OpenAPI v3.1.
150
+ *
151
+ * Contains reusable schema definitions and other components following the
152
+ * OpenAPI v3.1 specification. This structure is similar to v3.0 but supports
153
+ * enhanced JSON Schema features and improved type definitions.
154
+ *
155
+ * Components include:
156
+ * - schemas: Named type definitions with enhanced JSON Schema support
157
+ * - securitySchemes: Authentication and authorization schemes
158
+ *
159
+ * The emended OpenAPI v3.1 format used here removes ambiguous expressions
160
+ * and standardizes certain patterns for better tooling compatibility.
161
+ */
25
162
  components: OpenApi.IComponents;
163
+
164
+ /**
165
+ * Array of generated JSON schemas with v3.1 enhancements.
166
+ *
167
+ * Contains JSON schema definitions that take advantage of OpenAPI v3.1's
168
+ * enhanced capabilities. These schemas can express more complex TypeScript
169
+ * types accurately, including:
170
+ * - Tuple types using prefixItems
171
+ * - Union types with proper null handling
172
+ * - Complex nested object structures
173
+ * - Pattern-based property definitions
174
+ *
175
+ * Each schema corresponds to one of the input TypeScript types and may
176
+ * reference components defined in the {@link components} property.
177
+ */
26
178
  schemas: OpenApi.IJsonSchema[];
179
+
180
+ /**
181
+ * Type metadata for compile-time type tracking.
182
+ *
183
+ * This optional property stores the original TypeScript types that were
184
+ * used to generate the JSON schemas. It provides compile-time type safety
185
+ * and enables better development experience without affecting runtime behavior.
186
+ *
187
+ * Benefits include:
188
+ * - Strong typing connection to original TypeScript definitions
189
+ * - Enhanced IDE support and autocompletion
190
+ * - Compile-time validation of schema usage
191
+ * - Type-safe integration with validation libraries
192
+ */
27
193
  __types?: Types | undefined;
28
194
  }
29
195
  }
@@ -1,13 +1,56 @@
1
1
  import { OpenApi, OpenApiV3 } from "@samchon/openapi";
2
2
 
3
3
  /**
4
- * Unit of JSON schema.
4
+ * Single unit of JSON schema representation.
5
5
  *
6
- * `IJsonSchemaUnit` is a type that represents a single JSON schema unit
7
- * containing the schema and components.
6
+ * `IJsonSchemaUnit` represents a self-contained JSON schema unit that encapsulates
7
+ * a single schema definition along with its associated reusable components. This is
8
+ * typically used when generating a JSON schema for a single TypeScript type, as
9
+ * opposed to a collection of multiple types.
8
10
  *
9
- * @template Version Version of the OpenAPI specification
10
- * @template Type Original TypeScript type used in the JSON schema
11
+ * Unlike {@link IJsonSchemaCollection} which handles multiple schemas, `IJsonSchemaUnit`
12
+ * focuses on representing a single schema with its dependencies. This makes it ideal
13
+ * for scenarios where you need to work with individual type definitions or when
14
+ * integrating with systems that expect single schema documents.
15
+ *
16
+ * The unit contains:
17
+ * - A single JSON schema definition for the specified TypeScript type
18
+ * - All necessary reusable components that the schema may reference
19
+ * - Version-specific formatting for either OpenAPI v3.0 or v3.1 compatibility
20
+ * - Optional type metadata for compile-time type safety
21
+ *
22
+ * Key differences from collection:
23
+ * - Contains only one schema instead of an array of schemas
24
+ * - More lightweight for single-type use cases
25
+ * - Simpler structure for direct schema consumption
26
+ * - Still maintains full component reference support
27
+ *
28
+ * @template Version The OpenAPI specification version to target ("3.0" or "3.1").
29
+ * Defaults to "3.1" for enhanced JSON Schema Draft 2020-12 compatibility.
30
+ * This determines the schema format, validation capabilities, and
31
+ * available features like tuple support and null type handling.
32
+ * @template Type The original TypeScript type that was analyzed to generate this
33
+ * JSON schema unit. This provides compile-time type safety and
34
+ * enables IDEs to provide better intellisense and validation.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * interface User {
39
+ * id: string;
40
+ * name: string;
41
+ * email?: string;
42
+ * }
43
+ *
44
+ * // Generate a single schema unit for OpenAPI v3.1 (default)
45
+ * const userSchema = typia.json.schema<User>();
46
+ * // Type: IJsonSchemaUnit<"3.1", User>
47
+ *
48
+ * // Generate a single schema unit for OpenAPI v3.0 (Swagger compatibility)
49
+ * const swaggerUserSchema = typia.json.schema<User, "3.0">();
50
+ * // Type: IJsonSchemaUnit<"3.0", User>
51
+ * ```
52
+ *
53
+ * @see {@link IJsonSchemaCollection} For handling multiple schemas at once
11
54
  * @author Jeongho Nam - https://github.com/samchon
12
55
  */
13
56
  export type IJsonSchemaUnit<
@@ -16,17 +59,192 @@ export type IJsonSchemaUnit<
16
59
  > = Version extends "3.0"
17
60
  ? IJsonSchemaUnit.IV3_0<Type>
18
61
  : IJsonSchemaUnit.IV3_1<Type>;
62
+
19
63
  export namespace IJsonSchemaUnit {
64
+ /**
65
+ * JSON Schema unit formatted for OpenAPI v3.0 specification.
66
+ *
67
+ * This interface represents a single JSON schema unit that complies with
68
+ * OpenAPI v3.0 standards. It contains one schema definition along with
69
+ * any reusable components that the schema references, formatted according
70
+ * to OpenAPI v3.0 constraints and limitations.
71
+ *
72
+ * OpenAPI v3.0 characteristics affecting this unit:
73
+ * - Schema follows OpenAPI v3.0 JSON Schema subset
74
+ * - Limited support for advanced JSON Schema features
75
+ * - Uses nullable property for optional null values
76
+ * - Cannot natively express tuple types or pattern properties
77
+ * - Based on JSON Schema Draft 4 with OpenAPI-specific extensions
78
+ *
79
+ * Use cases for v3.0:
80
+ * - Integration with legacy Swagger tooling
81
+ * - Compatibility with older OpenAPI implementations
82
+ * - Systems that specifically require OpenAPI v3.0 format
83
+ * - Code generation tools that expect v3.0 schemas
84
+ *
85
+ * @template Type The original TypeScript type represented by this schema unit.
86
+ * Provides compile-time type information and enables type-safe
87
+ * operations on the schema.
88
+ */
20
89
  export interface IV3_0<Type> {
90
+ /**
91
+ * OpenAPI specification version identifier.
92
+ *
93
+ * Always set to "3.0" to indicate this schema unit uses OpenAPI v3.0
94
+ * format and adheres to its specific constraints and limitations.
95
+ */
21
96
  version: "3.0";
97
+
98
+ /**
99
+ * The primary JSON schema definition.
100
+ *
101
+ * Contains the main JSON schema that represents the TypeScript type specified
102
+ * in the `Type` template parameter. This schema follows OpenAPI v3.0 format
103
+ * and may contain references to reusable components defined in the
104
+ * {@link components} property.
105
+ *
106
+ * The schema structure includes:
107
+ * - Type definitions following OpenAPI v3.0 constraints
108
+ * - Property definitions with v3.0-compatible validation rules
109
+ * - References to shared components using $ref syntax
110
+ * - Nullable properties for optional fields that can be null
111
+ *
112
+ * Example schema reference: `{ "$ref": "#/components/schemas/NestedType" }`
113
+ */
22
114
  schema: OpenApiV3.IJsonSchema;
115
+
116
+ /**
117
+ * Reusable schema components for OpenAPI v3.0.
118
+ *
119
+ * Contains all reusable schema definitions and components that may be
120
+ * referenced by the main schema. This enables schema modularity and
121
+ * prevents duplication when the same types are used in multiple places
122
+ * within the schema definition.
123
+ *
124
+ * Component categories include:
125
+ * - schemas: Named type definitions for complex objects, arrays, and unions
126
+ * - securitySchemes: Authentication and authorization definitions
127
+ * - parameters: Reusable parameter specifications
128
+ * - requestBodies: Reusable request body definitions
129
+ * - responses: Reusable response specifications
130
+ * - headers: Reusable header definitions
131
+ * - examples: Reusable example values
132
+ *
133
+ * All components follow OpenAPI v3.0 format restrictions and capabilities.
134
+ */
23
135
  components: OpenApiV3.IComponents;
136
+
137
+ /**
138
+ * Type metadata for compile-time type safety.
139
+ *
140
+ * This optional property maintains a reference to the original TypeScript
141
+ * type that was used to generate this schema unit. It provides compile-time
142
+ * type information without affecting the runtime JSON representation.
143
+ *
144
+ * Benefits of type metadata:
145
+ * - Enables type-safe schema validation and usage
146
+ * - Provides IDE intellisense and autocompletion
147
+ * - Allows compile-time checking of schema operations
148
+ * - Maintains traceability to original TypeScript definitions
149
+ *
150
+ * The property is intentionally marked as optional and undefined to ensure
151
+ * it doesn't appear in serialized JSON output while preserving type information
152
+ * at compile time.
153
+ */
24
154
  __type?: Type | undefined;
25
155
  }
156
+
157
+ /**
158
+ * JSON Schema unit formatted for OpenAPI v3.1 specification.
159
+ *
160
+ * This interface represents a single JSON schema unit that takes advantage
161
+ * of OpenAPI v3.1's enhanced capabilities and improved JSON Schema compatibility.
162
+ * It provides a more feature-rich and accurate representation of TypeScript
163
+ * types compared to the v3.0 format.
164
+ *
165
+ * OpenAPI v3.1 advantages for this unit:
166
+ * - Full JSON Schema Draft 2020-12 compatibility
167
+ * - Native tuple type support using prefixItems
168
+ * - Proper null type handling via union types
169
+ * - Pattern properties for dynamic object keys
170
+ * - Enhanced const, enum, and validation capabilities
171
+ * - Better support for complex nested structures
172
+ *
173
+ * Use cases for v3.1:
174
+ * - Modern OpenAPI implementations and tooling
175
+ * - Systems requiring accurate TypeScript type representation
176
+ * - Applications needing advanced JSON Schema features
177
+ * - New projects without legacy compatibility requirements
178
+ *
179
+ * @template Type The original TypeScript type represented by this schema unit.
180
+ * Enables compile-time type safety and provides enhanced
181
+ * development experience with better IDE support.
182
+ */
26
183
  export interface IV3_1<Type> {
184
+ /**
185
+ * OpenAPI specification version identifier.
186
+ *
187
+ * Always set to "3.1" to indicate this schema unit uses OpenAPI v3.1
188
+ * format with enhanced JSON Schema compatibility and modern features.
189
+ */
27
190
  version: "3.1";
191
+
192
+ /**
193
+ * The primary JSON schema definition with v3.1 enhancements.
194
+ *
195
+ * Contains the main JSON schema that accurately represents the TypeScript
196
+ * type using OpenAPI v3.1's enhanced capabilities. This schema can express
197
+ * complex TypeScript constructs that were not possible or accurate in v3.0.
198
+ *
199
+ * Enhanced schema features include:
200
+ * - Tuple types using prefixItems for exact array structure
201
+ * - Union types with proper null handling via oneOf
202
+ * - Const values for literal types
203
+ * - Pattern properties for Record<string, T> types
204
+ * - Advanced validation constraints and metadata
205
+ * - Recursive type definitions with proper $ref handling
206
+ *
207
+ * The schema follows the emended OpenAPI v3.1 format used by typia,
208
+ * which removes ambiguous expressions while maintaining full compatibility.
209
+ */
28
210
  schema: OpenApi.IJsonSchema;
211
+
212
+ /**
213
+ * Reusable schema components for OpenAPI v3.1.
214
+ *
215
+ * Contains reusable schema definitions and components that leverage
216
+ * OpenAPI v3.1's enhanced capabilities. These components provide better
217
+ * type representation and more accurate schema definitions compared to v3.0.
218
+ *
219
+ * Enhanced component features:
220
+ * - schemas: More accurate type definitions with v3.1 JSON Schema features
221
+ * - securitySchemes: Enhanced authentication scheme definitions
222
+ * - Better support for complex nested references
223
+ * - Improved handling of recursive and circular type dependencies
224
+ *
225
+ * The components structure follows the emended OpenAPI v3.1 specification
226
+ * that simplifies certain patterns while maintaining full expressiveness.
227
+ */
29
228
  components: OpenApi.IComponents;
229
+
230
+ /**
231
+ * Type metadata for enhanced compile-time type safety.
232
+ *
233
+ * This optional property preserves the original TypeScript type information
234
+ * for compile-time type checking and enhanced development experience. It
235
+ * enables type-safe operations and better IDE support without affecting
236
+ * the runtime JSON schema representation.
237
+ *
238
+ * Enhanced type safety features:
239
+ * - Strong typing connection to original TypeScript definitions
240
+ * - Better IDE intellisense and error detection
241
+ * - Compile-time validation of schema usage patterns
242
+ * - Type-safe integration with validation and serialization libraries
243
+ * - Enhanced debugging and development experience
244
+ *
245
+ * The property remains optional and undefined to maintain clean JSON
246
+ * serialization while preserving valuable compile-time information.
247
+ */
30
248
  __type?: Type | undefined;
31
249
  }
32
250
  }