@skmtc/core 0.0.788 → 0.0.790

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 (49) hide show
  1. package/esm/context/ParseContext.d.ts +178 -0
  2. package/esm/context/ParseContext.d.ts.map +1 -1
  3. package/esm/context/ParseContext.js +108 -0
  4. package/esm/context/RenderContext.d.ts +190 -0
  5. package/esm/context/RenderContext.d.ts.map +1 -1
  6. package/esm/context/RenderContext.js +179 -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/helpers/refFns.d.ts +160 -0
  11. package/esm/helpers/refFns.d.ts.map +1 -1
  12. package/esm/helpers/refFns.js +156 -0
  13. package/esm/oas/boolean/Boolean.d.ts +142 -1
  14. package/esm/oas/boolean/Boolean.d.ts.map +1 -1
  15. package/esm/oas/boolean/Boolean.js +130 -1
  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/parameter/Parameter.d.ts +160 -0
  20. package/esm/oas/parameter/Parameter.d.ts.map +1 -1
  21. package/esm/oas/parameter/Parameter.js +144 -0
  22. package/esm/oas/union/Union.d.ts +119 -5
  23. package/esm/oas/union/Union.d.ts.map +1 -1
  24. package/esm/oas/union/Union.js +108 -5
  25. package/package.json +1 -1
  26. package/script/context/ParseContext.d.ts +178 -0
  27. package/script/context/ParseContext.d.ts.map +1 -1
  28. package/script/context/ParseContext.js +108 -0
  29. package/script/context/RenderContext.d.ts +190 -0
  30. package/script/context/RenderContext.d.ts.map +1 -1
  31. package/script/context/RenderContext.js +179 -0
  32. package/script/dsl/Inserted.d.ts +240 -0
  33. package/script/dsl/Inserted.d.ts.map +1 -1
  34. package/script/dsl/Inserted.js +231 -0
  35. package/script/helpers/refFns.d.ts +160 -0
  36. package/script/helpers/refFns.d.ts.map +1 -1
  37. package/script/helpers/refFns.js +156 -0
  38. package/script/oas/boolean/Boolean.d.ts +142 -1
  39. package/script/oas/boolean/Boolean.d.ts.map +1 -1
  40. package/script/oas/boolean/Boolean.js +130 -1
  41. package/script/oas/components/Components.d.ts +252 -2
  42. package/script/oas/components/Components.d.ts.map +1 -1
  43. package/script/oas/components/Components.js +241 -2
  44. package/script/oas/parameter/Parameter.d.ts +160 -0
  45. package/script/oas/parameter/Parameter.d.ts.map +1 -1
  46. package/script/oas/parameter/Parameter.js +144 -0
  47. package/script/oas/union/Union.d.ts +119 -5
  48. package/script/oas/union/Union.d.ts.map +1 -1
  49. package/script/oas/union/Union.js +108 -5
@@ -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;IAC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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) {