@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
@@ -1,6 +1,112 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  import { OasObject } from '../object/Object.js';
3
- /** Operation represents a resource path and a method that can be enacted against it */
3
+ /**
4
+ * Represents an OpenAPI Operation Object in the SKMTC OAS processing system.
5
+ *
6
+ * The `OasOperation` class encapsulates a single API operation (path + method combination)
7
+ * with all its associated metadata, parameters, request/response specifications, and
8
+ * security requirements. It provides utilities for extracting common operation data
9
+ * like success responses and request bodies.
10
+ *
11
+ * ## Key Features
12
+ *
13
+ * - **Path and Method**: Unique combination identifying the operation
14
+ * - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status
15
+ * - **Parameter Handling**: Query, path, header, and cookie parameters
16
+ * - **Request/Response Specs**: Type-safe access to request body and response definitions
17
+ * - **Security Context**: Operation-specific security requirements
18
+ * - **Success Response Utils**: Helper methods to identify and extract successful responses
19
+ *
20
+ * @example Basic operation properties
21
+ * ```typescript
22
+ * import { OasOperation } from '@skmtc/core';
23
+ *
24
+ * // Typically created during document parsing
25
+ * const getUserOp = new OasOperation({
26
+ * path: '/users/{id}',
27
+ * method: 'get',
28
+ * operationId: 'getUserById',
29
+ * summary: 'Get user by ID',
30
+ * description: 'Retrieves a single user by their unique identifier',
31
+ * parameters: [
32
+ * // Path parameter for user ID
33
+ * { name: 'id', in: 'path', required: true, schema: { type: 'string' } }
34
+ * ],
35
+ * responses: {
36
+ * '200': { description: 'User found', content: { ... } },
37
+ * '404': { description: 'User not found' }
38
+ * }
39
+ * });
40
+ *
41
+ * console.log(getUserOp.path); // '/users/{id}'
42
+ * console.log(getUserOp.method); // 'get'
43
+ * console.log(getUserOp.operationId); // 'getUserById'
44
+ * ```
45
+ *
46
+ * @example Working with success responses
47
+ * ```typescript
48
+ * // Find the primary success response
49
+ * const successResponse = operation.toSuccessResponse();
50
+ * if (successResponse) {
51
+ * const resolved = successResponse.resolve();
52
+ * console.log('Success response:', resolved.description);
53
+ * }
54
+ *
55
+ * // Get the HTTP status code for success
56
+ * const successCode = operation.toSuccessResponseCode();
57
+ * console.log('Success status:', successCode); // '200', '201', 'default', etc.
58
+ * ```
59
+ *
60
+ * @example Extracting request body data
61
+ * ```typescript
62
+ * // Extract request body with custom transformation
63
+ * const requestData = operation.toRequestBody(({ schema, requestBody }) => {
64
+ * return {
65
+ * schema: schema,
66
+ * contentType: 'application/json',
67
+ * required: requestBody.required ?? false,
68
+ * description: requestBody.description
69
+ * };
70
+ * });
71
+ *
72
+ * if (requestData) {
73
+ * console.log('Request schema:', requestData.schema);
74
+ * console.log('Required:', requestData.required);
75
+ * }
76
+ * ```
77
+ *
78
+ * @example Parameter processing
79
+ * ```typescript
80
+ * // Process operation parameters by location
81
+ * const pathParams = operation.parameters?.filter(param => {
82
+ * const resolved = param.resolve();
83
+ * return resolved.in === 'path';
84
+ * });
85
+ *
86
+ * const queryParams = operation.parameters?.filter(param => {
87
+ * const resolved = param.resolve();
88
+ * return resolved.in === 'query';
89
+ * });
90
+ *
91
+ * console.log('Path parameters:', pathParams?.length);
92
+ * console.log('Query parameters:', queryParams?.length);
93
+ * ```
94
+ *
95
+ * @example Security requirements
96
+ * ```typescript
97
+ * if (operation.security) {
98
+ * console.log('Operation has specific security requirements');
99
+ * for (const requirement of operation.security) {
100
+ * // Process security schemes for this operation
101
+ * Object.keys(requirement.schemes).forEach(scheme => {
102
+ * console.log(`Security scheme: ${scheme}`);
103
+ * });
104
+ * }
105
+ * } else {
106
+ * console.log('Operation uses default document security');
107
+ * }
108
+ * ```
109
+ */
4
110
  export class OasOperation {
5
111
  constructor(fields) {
6
112
  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,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,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AAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA"}
@@ -14,6 +14,92 @@ import "../../_dnt.polyfills.js";
14
14
  import { toRefName } from '../../helpers/refFns.js';
15
15
  import { match } from 'ts-pattern';
16
16
  const MAX_LOOKUPS = 10;
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 class OasRef {
18
104
  constructor(fields, oasDocument) {
19
105
  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,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,E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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"}
@@ -1,11 +1,114 @@
1
1
  /**
2
- * Object representing a 'oneOf' or 'anyOf' in the OpenAPI Specification.
2
+ * Represents a union type schema in the OpenAPI Specification.
3
3
  *
4
- * In the context of TypeScript 'anyOf' is not helpful since it implies
5
- * a union that consists of all possible combinations of member types.
4
+ * `OasUnion` handles both OpenAPI `oneOf` and `anyOf` constructs by mapping them
5
+ * to TypeScript union types. While OpenAPI distinguishes between these concepts,
6
+ * in TypeScript they both represent union types (A | B | C), making the distinction
7
+ * less meaningful for code generation.
6
8
  *
7
- * Generating such combination types would not be useful and we map both
8
- * 'oneOf' and 'anyOf' to a TypeScript union type.
9
+ * This class supports both simple unions and discriminated (tagged) unions through
10
+ * the discriminator property, which enables more precise type narrowing in generated code.
11
+ *
12
+ * ## Key Features
13
+ *
14
+ * - **Union Types**: Represents multiple possible schema types as a single union
15
+ * - **Tagged Unions**: Supports discriminator properties for type narrowing
16
+ * - **Reference Resolution**: Handles references to other schemas within union members
17
+ * - **Nullable Support**: Can represent nullable union types (A | B | null)
18
+ * - **JSON Schema**: Converts to standard JSON Schema format for validation
19
+ *
20
+ * @example Basic union type
21
+ * ```typescript
22
+ * import { OasUnion, OasString, OasInteger } from '@skmtc/core';
23
+ *
24
+ * const stringOrNumber = new OasUnion({
25
+ * title: 'StringOrNumber',
26
+ * description: 'A value that can be either a string or number',
27
+ * members: [
28
+ * new OasString({ title: 'String Value' }),
29
+ * new OasInteger({ title: 'Integer Value' })
30
+ * ]
31
+ * });
32
+ *
33
+ * // This represents: string | number
34
+ * ```
35
+ *
36
+ * @example Discriminated union (tagged union)
37
+ * ```typescript
38
+ * const shape = new OasUnion({
39
+ * title: 'Shape',
40
+ * description: 'Different types of geometric shapes',
41
+ * discriminator: new OasDiscriminator({
42
+ * propertyName: 'type',
43
+ * mapping: {
44
+ * 'circle': '#/components/schemas/Circle',
45
+ * 'square': '#/components/schemas/Square'
46
+ * }
47
+ * }),
48
+ * members: [
49
+ * new OasRef({ $ref: '#/components/schemas/Circle' }),
50
+ * new OasRef({ $ref: '#/components/schemas/Square' })
51
+ * ]
52
+ * });
53
+ *
54
+ * // This creates a tagged union that can be narrowed by the 'type' property
55
+ * ```
56
+ *
57
+ * @example Nullable union
58
+ * ```typescript
59
+ * const nullableStatus = new OasUnion({
60
+ * title: 'NullableStatus',
61
+ * nullable: true,
62
+ * members: [
63
+ * new OasString({ enum: ['active', 'inactive'] }),
64
+ * new OasString({ enum: ['pending', 'suspended'] })
65
+ * ],
66
+ * default: null
67
+ * });
68
+ *
69
+ * // This represents: ('active' | 'inactive' | 'pending' | 'suspended') | null
70
+ * ```
71
+ *
72
+ * @example Complex nested union
73
+ * ```typescript
74
+ * const apiResponse = new OasUnion({
75
+ * title: 'ApiResponse',
76
+ * description: 'Response from API endpoint',
77
+ * members: [
78
+ * new OasObject({
79
+ * title: 'SuccessResponse',
80
+ * properties: {
81
+ * success: new OasBoolean({ default: true }),
82
+ * data: new OasObject({ additionalProperties: true })
83
+ * }
84
+ * }),
85
+ * new OasObject({
86
+ * title: 'ErrorResponse',
87
+ * properties: {
88
+ * error: new OasString(),
89
+ * code: new OasInteger()
90
+ * }
91
+ * })
92
+ * ]
93
+ * });
94
+ *
95
+ * // This represents: { success: boolean; data: Record<string, any> } | { error: string; code: number }
96
+ * ```
97
+ *
98
+ * @example Using with references
99
+ * ```typescript
100
+ * const userOrAdmin = new OasUnion({
101
+ * title: 'UserOrAdmin',
102
+ * description: 'Either a regular user or an admin user',
103
+ * members: [
104
+ * new OasRef({ $ref: '#/components/schemas/User' }),
105
+ * new OasRef({ $ref: '#/components/schemas/Admin' })
106
+ * ]
107
+ * });
108
+ *
109
+ * // References will be resolved during processing
110
+ * // This represents: User | Admin
111
+ * ```
9
112
  */
10
113
  export class OasUnion {
11
114
  constructor(fields) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.787",
3
+ "version": "0.0.789",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/skmtc/skmtc.git"