@skmtc/core 0.0.787 → 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.
Files changed (55) hide show
  1. package/esm/context/GenerateContext.d.ts +95 -0
  2. package/esm/context/GenerateContext.d.ts.map +1 -1
  3. package/esm/context/GenerateContext.js +95 -0
  4. package/esm/context/ParseContext.d.ts +178 -0
  5. package/esm/context/ParseContext.d.ts.map +1 -1
  6. package/esm/context/ParseContext.js +108 -0
  7. package/esm/dsl/Inserted.d.ts +240 -0
  8. package/esm/dsl/Inserted.d.ts.map +1 -1
  9. package/esm/dsl/Inserted.js +231 -0
  10. package/esm/dsl/JsonFile.d.ts +162 -0
  11. package/esm/dsl/JsonFile.d.ts.map +1 -1
  12. package/esm/dsl/JsonFile.js +157 -0
  13. package/esm/helpers/refFns.d.ts +160 -0
  14. package/esm/helpers/refFns.d.ts.map +1 -1
  15. package/esm/helpers/refFns.js +156 -0
  16. package/esm/oas/components/Components.d.ts +252 -2
  17. package/esm/oas/components/Components.d.ts.map +1 -1
  18. package/esm/oas/components/Components.js +241 -2
  19. package/esm/oas/operation/Operation.d.ts +107 -1
  20. package/esm/oas/operation/Operation.d.ts.map +1 -1
  21. package/esm/oas/operation/Operation.js +107 -1
  22. package/esm/oas/ref/Ref.d.ts +86 -0
  23. package/esm/oas/ref/Ref.d.ts.map +1 -1
  24. package/esm/oas/ref/Ref.js +86 -0
  25. package/esm/oas/union/Union.d.ts +119 -5
  26. package/esm/oas/union/Union.d.ts.map +1 -1
  27. package/esm/oas/union/Union.js +108 -5
  28. package/package.json +1 -1
  29. package/script/context/GenerateContext.d.ts +95 -0
  30. package/script/context/GenerateContext.d.ts.map +1 -1
  31. package/script/context/GenerateContext.js +95 -0
  32. package/script/context/ParseContext.d.ts +178 -0
  33. package/script/context/ParseContext.d.ts.map +1 -1
  34. package/script/context/ParseContext.js +108 -0
  35. package/script/dsl/Inserted.d.ts +240 -0
  36. package/script/dsl/Inserted.d.ts.map +1 -1
  37. package/script/dsl/Inserted.js +231 -0
  38. package/script/dsl/JsonFile.d.ts +162 -0
  39. package/script/dsl/JsonFile.d.ts.map +1 -1
  40. package/script/dsl/JsonFile.js +157 -0
  41. package/script/helpers/refFns.d.ts +160 -0
  42. package/script/helpers/refFns.d.ts.map +1 -1
  43. package/script/helpers/refFns.js +156 -0
  44. package/script/oas/components/Components.d.ts +252 -2
  45. package/script/oas/components/Components.d.ts.map +1 -1
  46. package/script/oas/components/Components.js +241 -2
  47. package/script/oas/operation/Operation.d.ts +107 -1
  48. package/script/oas/operation/Operation.d.ts.map +1 -1
  49. package/script/oas/operation/Operation.js +107 -1
  50. package/script/oas/ref/Ref.d.ts +86 -0
  51. package/script/oas/ref/Ref.d.ts.map +1 -1
  52. package/script/oas/ref/Ref.js +86 -0
  53. package/script/oas/union/Union.d.ts +119 -5
  54. package/script/oas/union/Union.d.ts.map +1 -1
  55. package/script/oas/union/Union.js +108 -5
@@ -3,7 +3,113 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasOperation = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
5
  const Object_js_1 = require("../object/Object.js");
6
- /** Operation represents a resource path and a method that can be enacted against it */
6
+ /**
7
+ * Represents an OpenAPI Operation Object in the SKMTC OAS processing system.
8
+ *
9
+ * The `OasOperation` class encapsulates a single API operation (path + method combination)
10
+ * with all its associated metadata, parameters, request/response specifications, and
11
+ * security requirements. It provides utilities for extracting common operation data
12
+ * like success responses and request bodies.
13
+ *
14
+ * ## Key Features
15
+ *
16
+ * - **Path and Method**: Unique combination identifying the operation
17
+ * - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status
18
+ * - **Parameter Handling**: Query, path, header, and cookie parameters
19
+ * - **Request/Response Specs**: Type-safe access to request body and response definitions
20
+ * - **Security Context**: Operation-specific security requirements
21
+ * - **Success Response Utils**: Helper methods to identify and extract successful responses
22
+ *
23
+ * @example Basic operation properties
24
+ * ```typescript
25
+ * import { OasOperation } from '@skmtc/core';
26
+ *
27
+ * // Typically created during document parsing
28
+ * const getUserOp = new OasOperation({
29
+ * path: '/users/{id}',
30
+ * method: 'get',
31
+ * operationId: 'getUserById',
32
+ * summary: 'Get user by ID',
33
+ * description: 'Retrieves a single user by their unique identifier',
34
+ * parameters: [
35
+ * // Path parameter for user ID
36
+ * { name: 'id', in: 'path', required: true, schema: { type: 'string' } }
37
+ * ],
38
+ * responses: {
39
+ * '200': { description: 'User found', content: { ... } },
40
+ * '404': { description: 'User not found' }
41
+ * }
42
+ * });
43
+ *
44
+ * console.log(getUserOp.path); // '/users/{id}'
45
+ * console.log(getUserOp.method); // 'get'
46
+ * console.log(getUserOp.operationId); // 'getUserById'
47
+ * ```
48
+ *
49
+ * @example Working with success responses
50
+ * ```typescript
51
+ * // Find the primary success response
52
+ * const successResponse = operation.toSuccessResponse();
53
+ * if (successResponse) {
54
+ * const resolved = successResponse.resolve();
55
+ * console.log('Success response:', resolved.description);
56
+ * }
57
+ *
58
+ * // Get the HTTP status code for success
59
+ * const successCode = operation.toSuccessResponseCode();
60
+ * console.log('Success status:', successCode); // '200', '201', 'default', etc.
61
+ * ```
62
+ *
63
+ * @example Extracting request body data
64
+ * ```typescript
65
+ * // Extract request body with custom transformation
66
+ * const requestData = operation.toRequestBody(({ schema, requestBody }) => {
67
+ * return {
68
+ * schema: schema,
69
+ * contentType: 'application/json',
70
+ * required: requestBody.required ?? false,
71
+ * description: requestBody.description
72
+ * };
73
+ * });
74
+ *
75
+ * if (requestData) {
76
+ * console.log('Request schema:', requestData.schema);
77
+ * console.log('Required:', requestData.required);
78
+ * }
79
+ * ```
80
+ *
81
+ * @example Parameter processing
82
+ * ```typescript
83
+ * // Process operation parameters by location
84
+ * const pathParams = operation.parameters?.filter(param => {
85
+ * const resolved = param.resolve();
86
+ * return resolved.in === 'path';
87
+ * });
88
+ *
89
+ * const queryParams = operation.parameters?.filter(param => {
90
+ * const resolved = param.resolve();
91
+ * return resolved.in === 'query';
92
+ * });
93
+ *
94
+ * console.log('Path parameters:', pathParams?.length);
95
+ * console.log('Query parameters:', queryParams?.length);
96
+ * ```
97
+ *
98
+ * @example Security requirements
99
+ * ```typescript
100
+ * if (operation.security) {
101
+ * console.log('Operation has specific security requirements');
102
+ * for (const requirement of operation.security) {
103
+ * // Process security schemes for this operation
104
+ * Object.keys(requirement.schemes).forEach(scheme => {
105
+ * console.log(`Security scheme: ${scheme}`);
106
+ * });
107
+ * }
108
+ * } else {
109
+ * console.log('Operation uses default document security');
110
+ * }
111
+ * ```
112
+ */
7
113
  class OasOperation {
8
114
  constructor(fields) {
9
115
  Object.defineProperty(this, "oasType", {
@@ -14,6 +14,92 @@ export type RefFields<T extends OasRefData['refType']> = {
14
14
  refType: T;
15
15
  $ref: string;
16
16
  };
17
+ /**
18
+ * Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
19
+ *
20
+ * The `OasRef` class handles OpenAPI JSON Reference Objects that point to reusable
21
+ * components within the same document. It provides type-safe reference resolution
22
+ * with support for chained references and circular reference detection.
23
+ *
24
+ * ## Key Features
25
+ *
26
+ * - **Type Safety**: Generic parameter ensures resolved types match the reference type
27
+ * - **Lazy Resolution**: References are resolved on-demand, not during construction
28
+ * - **Chain Resolution**: Handles references that point to other references
29
+ * - **Circular Detection**: Prevents infinite loops with maximum lookup limits
30
+ * - **Type Validation**: Ensures resolved objects match expected reference types
31
+ *
32
+ * @template T - The type of component this reference points to
33
+ *
34
+ * @example Basic reference resolution
35
+ * ```typescript
36
+ * import { OasRef } from '@skmtc/core';
37
+ *
38
+ * // Reference to a schema component
39
+ * const userRef = new OasRef<'schema'>({
40
+ * refType: 'schema',
41
+ * $ref: '#/components/schemas/User'
42
+ * }, document);
43
+ *
44
+ * // Resolve the reference
45
+ * const userSchema = userRef.resolve();
46
+ * console.log(userSchema.properties); // Access resolved schema properties
47
+ * ```
48
+ *
49
+ * @example Working with different reference types
50
+ * ```typescript
51
+ * // Schema reference
52
+ * const schemaRef = new OasRef<'schema'>({
53
+ * refType: 'schema',
54
+ * $ref: '#/components/schemas/Product'
55
+ * }, document);
56
+ *
57
+ * // Response reference
58
+ * const responseRef = new OasRef<'response'>({
59
+ * refType: 'response',
60
+ * $ref: '#/components/responses/ErrorResponse'
61
+ * }, document);
62
+ *
63
+ * // Parameter reference
64
+ * const paramRef = new OasRef<'parameter'>({
65
+ * refType: 'parameter',
66
+ * $ref: '#/components/parameters/PageSize'
67
+ * }, document);
68
+ * ```
69
+ *
70
+ * @example Reference checking and conditional resolution
71
+ * ```typescript
72
+ * function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
73
+ * if (schema.isRef()) {
74
+ * // Handle reference
75
+ * const refName = schema.toRefName();
76
+ * console.log(`Processing reference: ${refName}`);
77
+ *
78
+ * // Resolve only when needed
79
+ * const resolved = schema.resolve();
80
+ * return processed(resolved);
81
+ * } else {
82
+ * // Handle direct schema
83
+ * return process(schema);
84
+ * }
85
+ * }
86
+ * ```
87
+ *
88
+ * @example Chained reference handling
89
+ * ```typescript
90
+ * // References can point to other references
91
+ * const chainedRef = new OasRef<'schema'>({
92
+ * refType: 'schema',
93
+ * $ref: '#/components/schemas/AliasToUser'
94
+ * }, document);
95
+ *
96
+ * // resolve() automatically follows the chain
97
+ * const finalSchema = chainedRef.resolve(); // Follows chain to final schema
98
+ *
99
+ * // resolveOnce() resolves only one step
100
+ * const oneStep = chainedRef.resolveOnce(); // May still be a reference
101
+ * ```
102
+ */
17
103
  export declare class OasRef<T extends OasRefData['refType']> {
18
104
  #private;
19
105
  oasType: 'ref';
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/oas/ref/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK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,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA"}
@@ -17,6 +17,92 @@ require("../../_dnt.polyfills.js");
17
17
  const refFns_js_1 = require("../../helpers/refFns.js");
18
18
  const ts_pattern_1 = require("ts-pattern");
19
19
  const MAX_LOOKUPS = 10;
20
+ /**
21
+ * Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
22
+ *
23
+ * The `OasRef` class handles OpenAPI JSON Reference Objects that point to reusable
24
+ * components within the same document. It provides type-safe reference resolution
25
+ * with support for chained references and circular reference detection.
26
+ *
27
+ * ## Key Features
28
+ *
29
+ * - **Type Safety**: Generic parameter ensures resolved types match the reference type
30
+ * - **Lazy Resolution**: References are resolved on-demand, not during construction
31
+ * - **Chain Resolution**: Handles references that point to other references
32
+ * - **Circular Detection**: Prevents infinite loops with maximum lookup limits
33
+ * - **Type Validation**: Ensures resolved objects match expected reference types
34
+ *
35
+ * @template T - The type of component this reference points to
36
+ *
37
+ * @example Basic reference resolution
38
+ * ```typescript
39
+ * import { OasRef } from '@skmtc/core';
40
+ *
41
+ * // Reference to a schema component
42
+ * const userRef = new OasRef<'schema'>({
43
+ * refType: 'schema',
44
+ * $ref: '#/components/schemas/User'
45
+ * }, document);
46
+ *
47
+ * // Resolve the reference
48
+ * const userSchema = userRef.resolve();
49
+ * console.log(userSchema.properties); // Access resolved schema properties
50
+ * ```
51
+ *
52
+ * @example Working with different reference types
53
+ * ```typescript
54
+ * // Schema reference
55
+ * const schemaRef = new OasRef<'schema'>({
56
+ * refType: 'schema',
57
+ * $ref: '#/components/schemas/Product'
58
+ * }, document);
59
+ *
60
+ * // Response reference
61
+ * const responseRef = new OasRef<'response'>({
62
+ * refType: 'response',
63
+ * $ref: '#/components/responses/ErrorResponse'
64
+ * }, document);
65
+ *
66
+ * // Parameter reference
67
+ * const paramRef = new OasRef<'parameter'>({
68
+ * refType: 'parameter',
69
+ * $ref: '#/components/parameters/PageSize'
70
+ * }, document);
71
+ * ```
72
+ *
73
+ * @example Reference checking and conditional resolution
74
+ * ```typescript
75
+ * function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
76
+ * if (schema.isRef()) {
77
+ * // Handle reference
78
+ * const refName = schema.toRefName();
79
+ * console.log(`Processing reference: ${refName}`);
80
+ *
81
+ * // Resolve only when needed
82
+ * const resolved = schema.resolve();
83
+ * return processed(resolved);
84
+ * } else {
85
+ * // Handle direct schema
86
+ * return process(schema);
87
+ * }
88
+ * }
89
+ * ```
90
+ *
91
+ * @example Chained reference handling
92
+ * ```typescript
93
+ * // References can point to other references
94
+ * const chainedRef = new OasRef<'schema'>({
95
+ * refType: 'schema',
96
+ * $ref: '#/components/schemas/AliasToUser'
97
+ * }, document);
98
+ *
99
+ * // resolve() automatically follows the chain
100
+ * const finalSchema = chainedRef.resolve(); // Follows chain to final schema
101
+ *
102
+ * // resolveOnce() resolves only one step
103
+ * const oneStep = chainedRef.resolveOnce(); // May still be a reference
104
+ * ```
105
+ */
20
106
  class OasRef {
21
107
  constructor(fields, oasDocument) {
22
108
  Object.defineProperty(this, "oasType", {
@@ -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,gBA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,qBAAa,QAAQ;IACnB;;;OAGG;IACH,OAAO,EAAG,QAAQ,CAAS;IAC3B;;OAEG;IACH,IAAI,EAAG,OAAO,CAAS;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B;;OAEG;IACH,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B;;OAEG;IACH,aAAa,EAAE,gBAAgB,GAAG,SAAS,CAAA;IAC3C;;OAEG;IACH,OAAO,EAAE,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAA;IAEzC,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;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) {