@skmtc/core 0.0.788 → 0.0.789

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.
@@ -15,6 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.OasComponents = exports.componentsKeys = void 0;
16
16
  require("../../_dnt.polyfills.js");
17
17
  require("../../_dnt.polyfills.js");
18
+ /**
19
+ * Available component types in an OpenAPI document.
20
+ */
18
21
  exports.componentsKeys = [
19
22
  'schemas',
20
23
  'responses',
@@ -24,11 +27,182 @@ exports.componentsKeys = [
24
27
  'headers',
25
28
  'securitySchemes'
26
29
  ];
27
- /** Container object for re-usable schema items within the API
30
+ /**
31
+ * Represents the OpenAPI Components Object in the SKMTC OAS processing system.
32
+ *
33
+ * The `OasComponents` class manages the reusable components section of an OpenAPI
34
+ * document, providing centralized access to shared schemas, responses, parameters,
35
+ * and other reusable elements that can be referenced throughout the API specification.
36
+ *
37
+ * This class serves as the central registry for all reusable components, enabling
38
+ * efficient reference resolution and reducing duplication in OpenAPI documents.
39
+ *
40
+ * ## Key Features
41
+ *
42
+ * - **Schema Management**: Central repository for reusable data schemas
43
+ * - **Response Reuse**: Common response definitions for consistent API responses
44
+ * - **Parameter Standardization**: Shared parameter definitions across operations
45
+ * - **Reference Resolution**: Support for internal references ($ref) to components
46
+ * - **Type Safety**: Strongly typed access to different component categories
47
+ * - **Extension Support**: Custom OpenAPI extension field handling
48
+ *
49
+ * @example Basic component access
50
+ * ```typescript
51
+ * import { OasComponents } from '@skmtc/core';
52
+ *
53
+ * // Typically created during document parsing
54
+ * const components = new OasComponents({
55
+ * schemas: {
56
+ * User: new OasObject({
57
+ * properties: {
58
+ * id: new OasString(),
59
+ * name: new OasString()
60
+ * }
61
+ * }),
62
+ * Product: new OasObject({
63
+ * properties: {
64
+ * id: new OasString(),
65
+ * price: new OasNumber()
66
+ * }
67
+ * })
68
+ * },
69
+ * responses: {
70
+ * NotFound: new OasResponse({
71
+ * description: '404 - Resource not found'
72
+ * })
73
+ * }
74
+ * });
75
+ *
76
+ * // Access schemas
77
+ * const userSchema = components.schemas?.['User'];
78
+ * const productSchema = components.schemas?.['Product'];
79
+ *
80
+ * // Access responses
81
+ * const notFoundResponse = components.responses?.['NotFound'];
82
+ * ```
83
+ *
84
+ * @example Schema management
85
+ * ```typescript
86
+ * // Get all schema reference names
87
+ * const schemaNames = components.toSchemasRefNames();
88
+ * console.log(schemaNames); // ['User', 'Product', 'Order']
89
+ *
90
+ * // Remove a schema (useful for processing)
91
+ * const removedSchema = components.removeSchema('ObsoleteSchema');
92
+ * console.log('Removed:', removedSchema);
93
+ *
94
+ * // Check remaining schemas
95
+ * const remainingSchemas = components.toSchemasRefNames();
96
+ * console.log('Remaining:', remainingSchemas);
97
+ * ```
98
+ *
99
+ * @example Parameter reuse
100
+ * ```typescript
101
+ * const components = new OasComponents({
102
+ * parameters: {
103
+ * PageSize: new OasParameter({
104
+ * name: 'pageSize',
105
+ * in: 'query',
106
+ * schema: new OasInteger({ minimum: 1, maximum: 100, default: 20 })
107
+ * }),
108
+ * PageNumber: new OasParameter({
109
+ * name: 'page',
110
+ * in: 'query',
111
+ * schema: new OasInteger({ minimum: 1, default: 1 })
112
+ * })
113
+ * }
114
+ * });
115
+ *
116
+ * // These parameters can be referenced in operations:
117
+ * // $ref: '#/components/parameters/PageSize'
118
+ * // $ref: '#/components/parameters/PageNumber'
119
+ * ```
120
+ *
121
+ * @example Response standardization
122
+ * ```typescript
123
+ * const components = new OasComponents({
124
+ * responses: {
125
+ * Success: new OasResponse({
126
+ * description: 'Successful operation',
127
+ * content: {
128
+ * 'application/json': {
129
+ * schema: new OasObject({
130
+ * properties: {
131
+ * success: new OasBoolean({ default: true }),
132
+ * data: new OasObject({ additionalProperties: true })
133
+ * }
134
+ * })
135
+ * }
136
+ * }
137
+ * }),
138
+ * ValidationError: new OasResponse({
139
+ * description: 'Validation failed',
140
+ * content: {
141
+ * 'application/json': {
142
+ * schema: new OasObject({
143
+ * properties: {
144
+ * error: new OasString(),
145
+ * details: new OasArray({
146
+ * items: new OasString()
147
+ * })
148
+ * }
149
+ * })
150
+ * }
151
+ * }
152
+ * })
153
+ * }
154
+ * });
155
+ *
156
+ * // Standardized responses across all operations
157
+ * ```
158
+ *
159
+ * @example Processing components in generators
160
+ * ```typescript
161
+ * class ComponentProcessor {
162
+ * processDocument(document: OasDocument) {
163
+ * const components = document.components;
164
+ * if (!components) return;
165
+ *
166
+ * // Process all schemas
167
+ * if (components.schemas) {
168
+ * Object.entries(components.schemas).forEach(([name, schema]) => {
169
+ * if (schema.isRef()) {
170
+ * console.log(`Schema ${name} is a reference to ${schema.$ref}`);
171
+ * } else {
172
+ * console.log(`Schema ${name} is a direct definition`);
173
+ * }
174
+ * });
175
+ * }
28
176
  *
29
- * Fields not yet implemented: **securitySchemes**, **links**, **callbacks**
177
+ * // Process parameters
178
+ * if (components.parameters) {
179
+ * Object.keys(components.parameters).forEach(paramName => {
180
+ * console.log(`Reusable parameter: ${paramName}`);
181
+ * });
182
+ * }
183
+ * }
184
+ * }
185
+ * ```
30
186
  */
31
187
  class OasComponents {
188
+ /**
189
+ * Creates a new OasComponents instance.
190
+ *
191
+ * @param fields - Component definitions (defaults to empty object)
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const components = new OasComponents({
196
+ * schemas: {
197
+ * User: userSchema,
198
+ * Product: productSchema
199
+ * },
200
+ * responses: {
201
+ * NotFound: notFoundResponse
202
+ * }
203
+ * });
204
+ * ```
205
+ */
32
206
  constructor(fields = {}) {
33
207
  /** Static identifier property for OasComponents */
34
208
  Object.defineProperty(this, "oasType", {
@@ -41,6 +215,35 @@ class OasComponents {
41
215
  _OasComponents_fields.set(this, void 0);
42
216
  __classPrivateFieldSet(this, _OasComponents_fields, fields, "f");
43
217
  }
218
+ /**
219
+ * Gets all schema reference names.
220
+ *
221
+ * This method extracts the keys from the schemas object and returns them
222
+ * as an array of RefName types. Useful for iterating over all available
223
+ * schemas or checking schema availability.
224
+ *
225
+ * @returns Array of reference names for all schemas
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * const components = new OasComponents({
230
+ * schemas: {
231
+ * User: userSchema,
232
+ * Product: productSchema,
233
+ * Order: orderSchema
234
+ * }
235
+ * });
236
+ *
237
+ * const schemaNames = components.toSchemasRefNames();
238
+ * console.log(schemaNames); // ['User', 'Product', 'Order']
239
+ *
240
+ * // Use for processing
241
+ * schemaNames.forEach(name => {
242
+ * const schema = components.schemas?.[name];
243
+ * console.log(`Processing schema: ${name}`);
244
+ * });
245
+ * ```
246
+ */
44
247
  toSchemasRefNames() {
45
248
  return Object.keys(__classPrivateFieldGet(this, _OasComponents_fields, "f").schemas ?? {});
46
249
  }
@@ -48,6 +251,42 @@ class OasComponents {
48
251
  get schemas() {
49
252
  return __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas;
50
253
  }
254
+ /**
255
+ * Removes a schema from the components and returns it.
256
+ *
257
+ * This method permanently removes a schema from the components object
258
+ * and returns the removed schema. This is useful during processing when
259
+ * you need to extract and handle specific schemas separately.
260
+ *
261
+ * @param refName - The reference name of the schema to remove
262
+ * @returns The removed schema object or reference
263
+ *
264
+ * @throws {Error} When the schema doesn't exist or schemas object is undefined
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * const components = new OasComponents({
269
+ * schemas: {
270
+ * User: userSchema,
271
+ * Product: productSchema,
272
+ * Internal: internalSchema
273
+ * }
274
+ * });
275
+ *
276
+ * // Remove internal schema that shouldn't be exposed
277
+ * const internalSchema = components.removeSchema('Internal');
278
+ * console.log('Removed internal schema');
279
+ *
280
+ * // Check remaining schemas
281
+ * const remainingSchemas = components.toSchemasRefNames();
282
+ * console.log(remainingSchemas); // ['User', 'Product']
283
+ *
284
+ * // Process removed schema separately
285
+ * if (!internalSchema.isRef()) {
286
+ * console.log('Processing internal schema privately');
287
+ * }
288
+ * ```
289
+ */
51
290
  removeSchema(refName) {
52
291
  const { [refName]: removed, ...rest } = __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas;
53
292
  __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas = rest;
@@ -3,24 +3,138 @@ import type { OasSchema } from '../schema/Schema.js';
3
3
  import type { OasRef } from '../ref/Ref.js';
4
4
  import type { ToJsonSchemaOptions } from '../schema/Schema.js';
5
5
  import type { OpenAPIV3 } from 'openapi-types';
6
+ /**
7
+ * Constructor fields for {@link OasUnion}.
8
+ */
6
9
  export type UnionFields = {
10
+ /** A short summary of the union type */
7
11
  title?: string;
12
+ /** A description of the union type */
8
13
  description?: string;
14
+ /** Whether the union value can be null */
9
15
  nullable?: boolean;
16
+ /** Discriminator object for creating tagged unions */
10
17
  discriminator?: OasDiscriminator;
18
+ /** Example value for the union */
11
19
  example?: unknown;
20
+ /** Default value for the union */
12
21
  default?: unknown;
22
+ /** Array of schemas that make up the union members */
13
23
  members: (OasSchema | OasRef<'schema'>)[];
24
+ /** Custom extension fields (x-* properties) */
14
25
  extensionFields?: Record<string, unknown>;
15
26
  };
16
27
  /**
17
- * Object representing a 'oneOf' or 'anyOf' in the OpenAPI Specification.
28
+ * Represents a union type schema in the OpenAPI Specification.
29
+ *
30
+ * `OasUnion` handles both OpenAPI `oneOf` and `anyOf` constructs by mapping them
31
+ * to TypeScript union types. While OpenAPI distinguishes between these concepts,
32
+ * in TypeScript they both represent union types (A | B | C), making the distinction
33
+ * less meaningful for code generation.
34
+ *
35
+ * This class supports both simple unions and discriminated (tagged) unions through
36
+ * the discriminator property, which enables more precise type narrowing in generated code.
37
+ *
38
+ * ## Key Features
39
+ *
40
+ * - **Union Types**: Represents multiple possible schema types as a single union
41
+ * - **Tagged Unions**: Supports discriminator properties for type narrowing
42
+ * - **Reference Resolution**: Handles references to other schemas within union members
43
+ * - **Nullable Support**: Can represent nullable union types (A | B | null)
44
+ * - **JSON Schema**: Converts to standard JSON Schema format for validation
45
+ *
46
+ * @example Basic union type
47
+ * ```typescript
48
+ * import { OasUnion, OasString, OasInteger } from '@skmtc/core';
49
+ *
50
+ * const stringOrNumber = new OasUnion({
51
+ * title: 'StringOrNumber',
52
+ * description: 'A value that can be either a string or number',
53
+ * members: [
54
+ * new OasString({ title: 'String Value' }),
55
+ * new OasInteger({ title: 'Integer Value' })
56
+ * ]
57
+ * });
58
+ *
59
+ * // This represents: string | number
60
+ * ```
61
+ *
62
+ * @example Discriminated union (tagged union)
63
+ * ```typescript
64
+ * const shape = new OasUnion({
65
+ * title: 'Shape',
66
+ * description: 'Different types of geometric shapes',
67
+ * discriminator: new OasDiscriminator({
68
+ * propertyName: 'type',
69
+ * mapping: {
70
+ * 'circle': '#/components/schemas/Circle',
71
+ * 'square': '#/components/schemas/Square'
72
+ * }
73
+ * }),
74
+ * members: [
75
+ * new OasRef({ $ref: '#/components/schemas/Circle' }),
76
+ * new OasRef({ $ref: '#/components/schemas/Square' })
77
+ * ]
78
+ * });
79
+ *
80
+ * // This creates a tagged union that can be narrowed by the 'type' property
81
+ * ```
82
+ *
83
+ * @example Nullable union
84
+ * ```typescript
85
+ * const nullableStatus = new OasUnion({
86
+ * title: 'NullableStatus',
87
+ * nullable: true,
88
+ * members: [
89
+ * new OasString({ enum: ['active', 'inactive'] }),
90
+ * new OasString({ enum: ['pending', 'suspended'] })
91
+ * ],
92
+ * default: null
93
+ * });
94
+ *
95
+ * // This represents: ('active' | 'inactive' | 'pending' | 'suspended') | null
96
+ * ```
97
+ *
98
+ * @example Complex nested union
99
+ * ```typescript
100
+ * const apiResponse = new OasUnion({
101
+ * title: 'ApiResponse',
102
+ * description: 'Response from API endpoint',
103
+ * members: [
104
+ * new OasObject({
105
+ * title: 'SuccessResponse',
106
+ * properties: {
107
+ * success: new OasBoolean({ default: true }),
108
+ * data: new OasObject({ additionalProperties: true })
109
+ * }
110
+ * }),
111
+ * new OasObject({
112
+ * title: 'ErrorResponse',
113
+ * properties: {
114
+ * error: new OasString(),
115
+ * code: new OasInteger()
116
+ * }
117
+ * })
118
+ * ]
119
+ * });
120
+ *
121
+ * // This represents: { success: boolean; data: Record<string, any> } | { error: string; code: number }
122
+ * ```
18
123
  *
19
- * In the context of TypeScript 'anyOf' is not helpful since it implies
20
- * a union that consists of all possible combinations of member types.
124
+ * @example Using with references
125
+ * ```typescript
126
+ * const userOrAdmin = new OasUnion({
127
+ * title: 'UserOrAdmin',
128
+ * description: 'Either a regular user or an admin user',
129
+ * members: [
130
+ * new OasRef({ $ref: '#/components/schemas/User' }),
131
+ * new OasRef({ $ref: '#/components/schemas/Admin' })
132
+ * ]
133
+ * });
21
134
  *
22
- * Generating such combination types would not be useful and we map both
23
- * 'oneOf' and 'anyOf' to a TypeScript union type.
135
+ * // References will be resolved during processing
136
+ * // This represents: User | Admin
137
+ * ```
24
138
  */
25
139
  export declare class OasUnion {
26
140
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Union.d.ts","sourceRoot":"","sources":["../../../src/oas/union/Union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,gBAAgB,CAAA;IAChC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAA;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;gBAEL,MAAM,EAAE,WAAW;IAW/B,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,QAAQ;IAInB,WAAW,IAAI,QAAQ;IAIvB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CAU3E"}
@@ -2,13 +2,116 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasUnion = void 0;
4
4
  /**
5
- * Object representing a 'oneOf' or 'anyOf' in the OpenAPI Specification.
5
+ * Represents a union type schema in the OpenAPI Specification.
6
6
  *
7
- * In the context of TypeScript 'anyOf' is not helpful since it implies
8
- * a union that consists of all possible combinations of member types.
7
+ * `OasUnion` handles both OpenAPI `oneOf` and `anyOf` constructs by mapping them
8
+ * to TypeScript union types. While OpenAPI distinguishes between these concepts,
9
+ * in TypeScript they both represent union types (A | B | C), making the distinction
10
+ * less meaningful for code generation.
9
11
  *
10
- * Generating such combination types would not be useful and we map both
11
- * 'oneOf' and 'anyOf' to a TypeScript union type.
12
+ * This class supports both simple unions and discriminated (tagged) unions through
13
+ * the discriminator property, which enables more precise type narrowing in generated code.
14
+ *
15
+ * ## Key Features
16
+ *
17
+ * - **Union Types**: Represents multiple possible schema types as a single union
18
+ * - **Tagged Unions**: Supports discriminator properties for type narrowing
19
+ * - **Reference Resolution**: Handles references to other schemas within union members
20
+ * - **Nullable Support**: Can represent nullable union types (A | B | null)
21
+ * - **JSON Schema**: Converts to standard JSON Schema format for validation
22
+ *
23
+ * @example Basic union type
24
+ * ```typescript
25
+ * import { OasUnion, OasString, OasInteger } from '@skmtc/core';
26
+ *
27
+ * const stringOrNumber = new OasUnion({
28
+ * title: 'StringOrNumber',
29
+ * description: 'A value that can be either a string or number',
30
+ * members: [
31
+ * new OasString({ title: 'String Value' }),
32
+ * new OasInteger({ title: 'Integer Value' })
33
+ * ]
34
+ * });
35
+ *
36
+ * // This represents: string | number
37
+ * ```
38
+ *
39
+ * @example Discriminated union (tagged union)
40
+ * ```typescript
41
+ * const shape = new OasUnion({
42
+ * title: 'Shape',
43
+ * description: 'Different types of geometric shapes',
44
+ * discriminator: new OasDiscriminator({
45
+ * propertyName: 'type',
46
+ * mapping: {
47
+ * 'circle': '#/components/schemas/Circle',
48
+ * 'square': '#/components/schemas/Square'
49
+ * }
50
+ * }),
51
+ * members: [
52
+ * new OasRef({ $ref: '#/components/schemas/Circle' }),
53
+ * new OasRef({ $ref: '#/components/schemas/Square' })
54
+ * ]
55
+ * });
56
+ *
57
+ * // This creates a tagged union that can be narrowed by the 'type' property
58
+ * ```
59
+ *
60
+ * @example Nullable union
61
+ * ```typescript
62
+ * const nullableStatus = new OasUnion({
63
+ * title: 'NullableStatus',
64
+ * nullable: true,
65
+ * members: [
66
+ * new OasString({ enum: ['active', 'inactive'] }),
67
+ * new OasString({ enum: ['pending', 'suspended'] })
68
+ * ],
69
+ * default: null
70
+ * });
71
+ *
72
+ * // This represents: ('active' | 'inactive' | 'pending' | 'suspended') | null
73
+ * ```
74
+ *
75
+ * @example Complex nested union
76
+ * ```typescript
77
+ * const apiResponse = new OasUnion({
78
+ * title: 'ApiResponse',
79
+ * description: 'Response from API endpoint',
80
+ * members: [
81
+ * new OasObject({
82
+ * title: 'SuccessResponse',
83
+ * properties: {
84
+ * success: new OasBoolean({ default: true }),
85
+ * data: new OasObject({ additionalProperties: true })
86
+ * }
87
+ * }),
88
+ * new OasObject({
89
+ * title: 'ErrorResponse',
90
+ * properties: {
91
+ * error: new OasString(),
92
+ * code: new OasInteger()
93
+ * }
94
+ * })
95
+ * ]
96
+ * });
97
+ *
98
+ * // This represents: { success: boolean; data: Record<string, any> } | { error: string; code: number }
99
+ * ```
100
+ *
101
+ * @example Using with references
102
+ * ```typescript
103
+ * const userOrAdmin = new OasUnion({
104
+ * title: 'UserOrAdmin',
105
+ * description: 'Either a regular user or an admin user',
106
+ * members: [
107
+ * new OasRef({ $ref: '#/components/schemas/User' }),
108
+ * new OasRef({ $ref: '#/components/schemas/Admin' })
109
+ * ]
110
+ * });
111
+ *
112
+ * // References will be resolved during processing
113
+ * // This represents: User | Admin
114
+ * ```
12
115
  */
13
116
  class OasUnion {
14
117
  constructor(fields) {