@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.
- package/esm/context/ParseContext.d.ts +178 -0
- package/esm/context/ParseContext.d.ts.map +1 -1
- package/esm/context/ParseContext.js +108 -0
- package/esm/dsl/Inserted.d.ts +240 -0
- package/esm/dsl/Inserted.d.ts.map +1 -1
- package/esm/dsl/Inserted.js +231 -0
- package/esm/helpers/refFns.d.ts +160 -0
- package/esm/helpers/refFns.d.ts.map +1 -1
- package/esm/helpers/refFns.js +156 -0
- package/esm/oas/components/Components.d.ts +252 -2
- package/esm/oas/components/Components.d.ts.map +1 -1
- package/esm/oas/components/Components.js +241 -2
- package/esm/oas/union/Union.d.ts +119 -5
- package/esm/oas/union/Union.d.ts.map +1 -1
- package/esm/oas/union/Union.js +108 -5
- package/package.json +1 -1
- package/script/context/ParseContext.d.ts +178 -0
- package/script/context/ParseContext.d.ts.map +1 -1
- package/script/context/ParseContext.js +108 -0
- package/script/dsl/Inserted.d.ts +240 -0
- package/script/dsl/Inserted.d.ts.map +1 -1
- package/script/dsl/Inserted.js +231 -0
- package/script/helpers/refFns.d.ts +160 -0
- package/script/helpers/refFns.d.ts.map +1 -1
- package/script/helpers/refFns.js +156 -0
- package/script/oas/components/Components.d.ts +252 -2
- package/script/oas/components/Components.d.ts.map +1 -1
- package/script/oas/components/Components.js +241 -2
- package/script/oas/union/Union.d.ts +119 -5
- package/script/oas/union/Union.d.ts.map +1 -1
- package/script/oas/union/Union.js +108 -5
|
@@ -9,29 +9,279 @@ import type { OasRef } from '../ref/Ref.js';
|
|
|
9
9
|
import type { OasSchema } from '../schema/Schema.js';
|
|
10
10
|
import type { RefName } from '../../types/RefName.js';
|
|
11
11
|
import type { OasSecurityScheme } from '../securitySchemes/SecurityScheme.js';
|
|
12
|
+
/**
|
|
13
|
+
* Available component types in an OpenAPI document.
|
|
14
|
+
*/
|
|
12
15
|
export declare const componentsKeys: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Constructor fields for {@link OasComponents}.
|
|
18
|
+
*/
|
|
13
19
|
export type ComponentsFields = {
|
|
20
|
+
/** Reusable schema components */
|
|
14
21
|
schemas?: Record<RefName, OasSchema | OasRef<'schema'>>;
|
|
22
|
+
/** Reusable response components */
|
|
15
23
|
responses?: Record<RefName, OasResponse | OasRef<'response'>>;
|
|
24
|
+
/** Reusable parameter components */
|
|
16
25
|
parameters?: Record<RefName, OasParameter | OasRef<'parameter'>>;
|
|
26
|
+
/** Reusable example components */
|
|
17
27
|
examples?: Record<RefName, OasExample | OasRef<'example'>>;
|
|
28
|
+
/** Reusable request body components */
|
|
18
29
|
requestBodies?: Record<RefName, OasRequestBody | OasRef<'requestBody'>>;
|
|
30
|
+
/** Reusable header components */
|
|
19
31
|
headers?: Record<RefName, OasHeader | OasRef<'header'>>;
|
|
32
|
+
/** Reusable security scheme components */
|
|
20
33
|
securitySchemes?: Record<string, OasSecurityScheme | OasRef<'securityScheme'>>;
|
|
34
|
+
/** Custom extension fields (x-* properties) */
|
|
21
35
|
extensionFields?: Record<string, unknown>;
|
|
22
36
|
};
|
|
23
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Represents the OpenAPI Components Object in the SKMTC OAS processing system.
|
|
39
|
+
*
|
|
40
|
+
* The `OasComponents` class manages the reusable components section of an OpenAPI
|
|
41
|
+
* document, providing centralized access to shared schemas, responses, parameters,
|
|
42
|
+
* and other reusable elements that can be referenced throughout the API specification.
|
|
43
|
+
*
|
|
44
|
+
* This class serves as the central registry for all reusable components, enabling
|
|
45
|
+
* efficient reference resolution and reducing duplication in OpenAPI documents.
|
|
46
|
+
*
|
|
47
|
+
* ## Key Features
|
|
48
|
+
*
|
|
49
|
+
* - **Schema Management**: Central repository for reusable data schemas
|
|
50
|
+
* - **Response Reuse**: Common response definitions for consistent API responses
|
|
51
|
+
* - **Parameter Standardization**: Shared parameter definitions across operations
|
|
52
|
+
* - **Reference Resolution**: Support for internal references ($ref) to components
|
|
53
|
+
* - **Type Safety**: Strongly typed access to different component categories
|
|
54
|
+
* - **Extension Support**: Custom OpenAPI extension field handling
|
|
55
|
+
*
|
|
56
|
+
* @example Basic component access
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { OasComponents } from '@skmtc/core';
|
|
59
|
+
*
|
|
60
|
+
* // Typically created during document parsing
|
|
61
|
+
* const components = new OasComponents({
|
|
62
|
+
* schemas: {
|
|
63
|
+
* User: new OasObject({
|
|
64
|
+
* properties: {
|
|
65
|
+
* id: new OasString(),
|
|
66
|
+
* name: new OasString()
|
|
67
|
+
* }
|
|
68
|
+
* }),
|
|
69
|
+
* Product: new OasObject({
|
|
70
|
+
* properties: {
|
|
71
|
+
* id: new OasString(),
|
|
72
|
+
* price: new OasNumber()
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* },
|
|
76
|
+
* responses: {
|
|
77
|
+
* NotFound: new OasResponse({
|
|
78
|
+
* description: '404 - Resource not found'
|
|
79
|
+
* })
|
|
80
|
+
* }
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Access schemas
|
|
84
|
+
* const userSchema = components.schemas?.['User'];
|
|
85
|
+
* const productSchema = components.schemas?.['Product'];
|
|
86
|
+
*
|
|
87
|
+
* // Access responses
|
|
88
|
+
* const notFoundResponse = components.responses?.['NotFound'];
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Schema management
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Get all schema reference names
|
|
94
|
+
* const schemaNames = components.toSchemasRefNames();
|
|
95
|
+
* console.log(schemaNames); // ['User', 'Product', 'Order']
|
|
96
|
+
*
|
|
97
|
+
* // Remove a schema (useful for processing)
|
|
98
|
+
* const removedSchema = components.removeSchema('ObsoleteSchema');
|
|
99
|
+
* console.log('Removed:', removedSchema);
|
|
100
|
+
*
|
|
101
|
+
* // Check remaining schemas
|
|
102
|
+
* const remainingSchemas = components.toSchemasRefNames();
|
|
103
|
+
* console.log('Remaining:', remainingSchemas);
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example Parameter reuse
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const components = new OasComponents({
|
|
109
|
+
* parameters: {
|
|
110
|
+
* PageSize: new OasParameter({
|
|
111
|
+
* name: 'pageSize',
|
|
112
|
+
* in: 'query',
|
|
113
|
+
* schema: new OasInteger({ minimum: 1, maximum: 100, default: 20 })
|
|
114
|
+
* }),
|
|
115
|
+
* PageNumber: new OasParameter({
|
|
116
|
+
* name: 'page',
|
|
117
|
+
* in: 'query',
|
|
118
|
+
* schema: new OasInteger({ minimum: 1, default: 1 })
|
|
119
|
+
* })
|
|
120
|
+
* }
|
|
121
|
+
* });
|
|
122
|
+
*
|
|
123
|
+
* // These parameters can be referenced in operations:
|
|
124
|
+
* // $ref: '#/components/parameters/PageSize'
|
|
125
|
+
* // $ref: '#/components/parameters/PageNumber'
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example Response standardization
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const components = new OasComponents({
|
|
131
|
+
* responses: {
|
|
132
|
+
* Success: new OasResponse({
|
|
133
|
+
* description: 'Successful operation',
|
|
134
|
+
* content: {
|
|
135
|
+
* 'application/json': {
|
|
136
|
+
* schema: new OasObject({
|
|
137
|
+
* properties: {
|
|
138
|
+
* success: new OasBoolean({ default: true }),
|
|
139
|
+
* data: new OasObject({ additionalProperties: true })
|
|
140
|
+
* }
|
|
141
|
+
* })
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* }),
|
|
145
|
+
* ValidationError: new OasResponse({
|
|
146
|
+
* description: 'Validation failed',
|
|
147
|
+
* content: {
|
|
148
|
+
* 'application/json': {
|
|
149
|
+
* schema: new OasObject({
|
|
150
|
+
* properties: {
|
|
151
|
+
* error: new OasString(),
|
|
152
|
+
* details: new OasArray({
|
|
153
|
+
* items: new OasString()
|
|
154
|
+
* })
|
|
155
|
+
* }
|
|
156
|
+
* })
|
|
157
|
+
* }
|
|
158
|
+
* }
|
|
159
|
+
* })
|
|
160
|
+
* }
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Standardized responses across all operations
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example Processing components in generators
|
|
167
|
+
* ```typescript
|
|
168
|
+
* class ComponentProcessor {
|
|
169
|
+
* processDocument(document: OasDocument) {
|
|
170
|
+
* const components = document.components;
|
|
171
|
+
* if (!components) return;
|
|
172
|
+
*
|
|
173
|
+
* // Process all schemas
|
|
174
|
+
* if (components.schemas) {
|
|
175
|
+
* Object.entries(components.schemas).forEach(([name, schema]) => {
|
|
176
|
+
* if (schema.isRef()) {
|
|
177
|
+
* console.log(`Schema ${name} is a reference to ${schema.$ref}`);
|
|
178
|
+
* } else {
|
|
179
|
+
* console.log(`Schema ${name} is a direct definition`);
|
|
180
|
+
* }
|
|
181
|
+
* });
|
|
182
|
+
* }
|
|
24
183
|
*
|
|
25
|
-
*
|
|
184
|
+
* // Process parameters
|
|
185
|
+
* if (components.parameters) {
|
|
186
|
+
* Object.keys(components.parameters).forEach(paramName => {
|
|
187
|
+
* console.log(`Reusable parameter: ${paramName}`);
|
|
188
|
+
* });
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
26
193
|
*/
|
|
27
194
|
export declare class OasComponents {
|
|
28
195
|
#private;
|
|
29
196
|
/** Static identifier property for OasComponents */
|
|
30
197
|
oasType: "components";
|
|
198
|
+
/**
|
|
199
|
+
* Creates a new OasComponents instance.
|
|
200
|
+
*
|
|
201
|
+
* @param fields - Component definitions (defaults to empty object)
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const components = new OasComponents({
|
|
206
|
+
* schemas: {
|
|
207
|
+
* User: userSchema,
|
|
208
|
+
* Product: productSchema
|
|
209
|
+
* },
|
|
210
|
+
* responses: {
|
|
211
|
+
* NotFound: notFoundResponse
|
|
212
|
+
* }
|
|
213
|
+
* });
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
31
216
|
constructor(fields?: ComponentsFields);
|
|
217
|
+
/**
|
|
218
|
+
* Gets all schema reference names.
|
|
219
|
+
*
|
|
220
|
+
* This method extracts the keys from the schemas object and returns them
|
|
221
|
+
* as an array of RefName types. Useful for iterating over all available
|
|
222
|
+
* schemas or checking schema availability.
|
|
223
|
+
*
|
|
224
|
+
* @returns Array of reference names for all schemas
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const components = new OasComponents({
|
|
229
|
+
* schemas: {
|
|
230
|
+
* User: userSchema,
|
|
231
|
+
* Product: productSchema,
|
|
232
|
+
* Order: orderSchema
|
|
233
|
+
* }
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
* const schemaNames = components.toSchemasRefNames();
|
|
237
|
+
* console.log(schemaNames); // ['User', 'Product', 'Order']
|
|
238
|
+
*
|
|
239
|
+
* // Use for processing
|
|
240
|
+
* schemaNames.forEach(name => {
|
|
241
|
+
* const schema = components.schemas?.[name];
|
|
242
|
+
* console.log(`Processing schema: ${name}`);
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
32
246
|
toSchemasRefNames(): RefName[];
|
|
33
247
|
/** Record holding re-usable {@link OasSchema} objects or Refs */
|
|
34
248
|
get schemas(): Record<RefName, OasSchema | OasRef<'schema'>> | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* Removes a schema from the components and returns it.
|
|
251
|
+
*
|
|
252
|
+
* This method permanently removes a schema from the components object
|
|
253
|
+
* and returns the removed schema. This is useful during processing when
|
|
254
|
+
* you need to extract and handle specific schemas separately.
|
|
255
|
+
*
|
|
256
|
+
* @param refName - The reference name of the schema to remove
|
|
257
|
+
* @returns The removed schema object or reference
|
|
258
|
+
*
|
|
259
|
+
* @throws {Error} When the schema doesn't exist or schemas object is undefined
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const components = new OasComponents({
|
|
264
|
+
* schemas: {
|
|
265
|
+
* User: userSchema,
|
|
266
|
+
* Product: productSchema,
|
|
267
|
+
* Internal: internalSchema
|
|
268
|
+
* }
|
|
269
|
+
* });
|
|
270
|
+
*
|
|
271
|
+
* // Remove internal schema that shouldn't be exposed
|
|
272
|
+
* const internalSchema = components.removeSchema('Internal');
|
|
273
|
+
* console.log('Removed internal schema');
|
|
274
|
+
*
|
|
275
|
+
* // Check remaining schemas
|
|
276
|
+
* const remainingSchemas = components.toSchemasRefNames();
|
|
277
|
+
* console.log(remainingSchemas); // ['User', 'Product']
|
|
278
|
+
*
|
|
279
|
+
* // Process removed schema separately
|
|
280
|
+
* if (!internalSchema.isRef()) {
|
|
281
|
+
* console.log('Processing internal schema privately');
|
|
282
|
+
* }
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
35
285
|
removeSchema(refName: RefName): OasSchema | OasRef<'schema'>;
|
|
36
286
|
/** Record holding re-usable {@link OasResponse} objects or Refs */
|
|
37
287
|
get responses(): Record<RefName, OasResponse | OasRef<'response'>> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.d.ts","sourceRoot":"","sources":["../../../src/oas/components/Components.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe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ACvE,IAAI,aAAa,IAAI,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS,CAEvF;IAED,kEAAkE;IAClE,IAAI,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAEvE;IAED,0EAA0E;IAC1E,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAE9F;IAED,qCAAqC;IACrC,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEzD;CACF"}
|
|
@@ -12,6 +12,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
var _OasComponents_fields;
|
|
13
13
|
import "../../_dnt.polyfills.js";
|
|
14
14
|
import "../../_dnt.polyfills.js";
|
|
15
|
+
/**
|
|
16
|
+
* Available component types in an OpenAPI document.
|
|
17
|
+
*/
|
|
15
18
|
export const componentsKeys = [
|
|
16
19
|
'schemas',
|
|
17
20
|
'responses',
|
|
@@ -21,11 +24,182 @@ export const componentsKeys = [
|
|
|
21
24
|
'headers',
|
|
22
25
|
'securitySchemes'
|
|
23
26
|
];
|
|
24
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Represents the OpenAPI Components Object in the SKMTC OAS processing system.
|
|
29
|
+
*
|
|
30
|
+
* The `OasComponents` class manages the reusable components section of an OpenAPI
|
|
31
|
+
* document, providing centralized access to shared schemas, responses, parameters,
|
|
32
|
+
* and other reusable elements that can be referenced throughout the API specification.
|
|
33
|
+
*
|
|
34
|
+
* This class serves as the central registry for all reusable components, enabling
|
|
35
|
+
* efficient reference resolution and reducing duplication in OpenAPI documents.
|
|
36
|
+
*
|
|
37
|
+
* ## Key Features
|
|
38
|
+
*
|
|
39
|
+
* - **Schema Management**: Central repository for reusable data schemas
|
|
40
|
+
* - **Response Reuse**: Common response definitions for consistent API responses
|
|
41
|
+
* - **Parameter Standardization**: Shared parameter definitions across operations
|
|
42
|
+
* - **Reference Resolution**: Support for internal references ($ref) to components
|
|
43
|
+
* - **Type Safety**: Strongly typed access to different component categories
|
|
44
|
+
* - **Extension Support**: Custom OpenAPI extension field handling
|
|
45
|
+
*
|
|
46
|
+
* @example Basic component access
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { OasComponents } from '@skmtc/core';
|
|
49
|
+
*
|
|
50
|
+
* // Typically created during document parsing
|
|
51
|
+
* const components = new OasComponents({
|
|
52
|
+
* schemas: {
|
|
53
|
+
* User: new OasObject({
|
|
54
|
+
* properties: {
|
|
55
|
+
* id: new OasString(),
|
|
56
|
+
* name: new OasString()
|
|
57
|
+
* }
|
|
58
|
+
* }),
|
|
59
|
+
* Product: new OasObject({
|
|
60
|
+
* properties: {
|
|
61
|
+
* id: new OasString(),
|
|
62
|
+
* price: new OasNumber()
|
|
63
|
+
* }
|
|
64
|
+
* })
|
|
65
|
+
* },
|
|
66
|
+
* responses: {
|
|
67
|
+
* NotFound: new OasResponse({
|
|
68
|
+
* description: '404 - Resource not found'
|
|
69
|
+
* })
|
|
70
|
+
* }
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Access schemas
|
|
74
|
+
* const userSchema = components.schemas?.['User'];
|
|
75
|
+
* const productSchema = components.schemas?.['Product'];
|
|
76
|
+
*
|
|
77
|
+
* // Access responses
|
|
78
|
+
* const notFoundResponse = components.responses?.['NotFound'];
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Schema management
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Get all schema reference names
|
|
84
|
+
* const schemaNames = components.toSchemasRefNames();
|
|
85
|
+
* console.log(schemaNames); // ['User', 'Product', 'Order']
|
|
86
|
+
*
|
|
87
|
+
* // Remove a schema (useful for processing)
|
|
88
|
+
* const removedSchema = components.removeSchema('ObsoleteSchema');
|
|
89
|
+
* console.log('Removed:', removedSchema);
|
|
90
|
+
*
|
|
91
|
+
* // Check remaining schemas
|
|
92
|
+
* const remainingSchemas = components.toSchemasRefNames();
|
|
93
|
+
* console.log('Remaining:', remainingSchemas);
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example Parameter reuse
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const components = new OasComponents({
|
|
99
|
+
* parameters: {
|
|
100
|
+
* PageSize: new OasParameter({
|
|
101
|
+
* name: 'pageSize',
|
|
102
|
+
* in: 'query',
|
|
103
|
+
* schema: new OasInteger({ minimum: 1, maximum: 100, default: 20 })
|
|
104
|
+
* }),
|
|
105
|
+
* PageNumber: new OasParameter({
|
|
106
|
+
* name: 'page',
|
|
107
|
+
* in: 'query',
|
|
108
|
+
* schema: new OasInteger({ minimum: 1, default: 1 })
|
|
109
|
+
* })
|
|
110
|
+
* }
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // These parameters can be referenced in operations:
|
|
114
|
+
* // $ref: '#/components/parameters/PageSize'
|
|
115
|
+
* // $ref: '#/components/parameters/PageNumber'
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example Response standardization
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const components = new OasComponents({
|
|
121
|
+
* responses: {
|
|
122
|
+
* Success: new OasResponse({
|
|
123
|
+
* description: 'Successful operation',
|
|
124
|
+
* content: {
|
|
125
|
+
* 'application/json': {
|
|
126
|
+
* schema: new OasObject({
|
|
127
|
+
* properties: {
|
|
128
|
+
* success: new OasBoolean({ default: true }),
|
|
129
|
+
* data: new OasObject({ additionalProperties: true })
|
|
130
|
+
* }
|
|
131
|
+
* })
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* }),
|
|
135
|
+
* ValidationError: new OasResponse({
|
|
136
|
+
* description: 'Validation failed',
|
|
137
|
+
* content: {
|
|
138
|
+
* 'application/json': {
|
|
139
|
+
* schema: new OasObject({
|
|
140
|
+
* properties: {
|
|
141
|
+
* error: new OasString(),
|
|
142
|
+
* details: new OasArray({
|
|
143
|
+
* items: new OasString()
|
|
144
|
+
* })
|
|
145
|
+
* }
|
|
146
|
+
* })
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* })
|
|
150
|
+
* }
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Standardized responses across all operations
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @example Processing components in generators
|
|
157
|
+
* ```typescript
|
|
158
|
+
* class ComponentProcessor {
|
|
159
|
+
* processDocument(document: OasDocument) {
|
|
160
|
+
* const components = document.components;
|
|
161
|
+
* if (!components) return;
|
|
162
|
+
*
|
|
163
|
+
* // Process all schemas
|
|
164
|
+
* if (components.schemas) {
|
|
165
|
+
* Object.entries(components.schemas).forEach(([name, schema]) => {
|
|
166
|
+
* if (schema.isRef()) {
|
|
167
|
+
* console.log(`Schema ${name} is a reference to ${schema.$ref}`);
|
|
168
|
+
* } else {
|
|
169
|
+
* console.log(`Schema ${name} is a direct definition`);
|
|
170
|
+
* }
|
|
171
|
+
* });
|
|
172
|
+
* }
|
|
25
173
|
*
|
|
26
|
-
*
|
|
174
|
+
* // Process parameters
|
|
175
|
+
* if (components.parameters) {
|
|
176
|
+
* Object.keys(components.parameters).forEach(paramName => {
|
|
177
|
+
* console.log(`Reusable parameter: ${paramName}`);
|
|
178
|
+
* });
|
|
179
|
+
* }
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
27
183
|
*/
|
|
28
184
|
export class OasComponents {
|
|
185
|
+
/**
|
|
186
|
+
* Creates a new OasComponents instance.
|
|
187
|
+
*
|
|
188
|
+
* @param fields - Component definitions (defaults to empty object)
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const components = new OasComponents({
|
|
193
|
+
* schemas: {
|
|
194
|
+
* User: userSchema,
|
|
195
|
+
* Product: productSchema
|
|
196
|
+
* },
|
|
197
|
+
* responses: {
|
|
198
|
+
* NotFound: notFoundResponse
|
|
199
|
+
* }
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
29
203
|
constructor(fields = {}) {
|
|
30
204
|
/** Static identifier property for OasComponents */
|
|
31
205
|
Object.defineProperty(this, "oasType", {
|
|
@@ -38,6 +212,35 @@ export class OasComponents {
|
|
|
38
212
|
_OasComponents_fields.set(this, void 0);
|
|
39
213
|
__classPrivateFieldSet(this, _OasComponents_fields, fields, "f");
|
|
40
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Gets all schema reference names.
|
|
217
|
+
*
|
|
218
|
+
* This method extracts the keys from the schemas object and returns them
|
|
219
|
+
* as an array of RefName types. Useful for iterating over all available
|
|
220
|
+
* schemas or checking schema availability.
|
|
221
|
+
*
|
|
222
|
+
* @returns Array of reference names for all schemas
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const components = new OasComponents({
|
|
227
|
+
* schemas: {
|
|
228
|
+
* User: userSchema,
|
|
229
|
+
* Product: productSchema,
|
|
230
|
+
* Order: orderSchema
|
|
231
|
+
* }
|
|
232
|
+
* });
|
|
233
|
+
*
|
|
234
|
+
* const schemaNames = components.toSchemasRefNames();
|
|
235
|
+
* console.log(schemaNames); // ['User', 'Product', 'Order']
|
|
236
|
+
*
|
|
237
|
+
* // Use for processing
|
|
238
|
+
* schemaNames.forEach(name => {
|
|
239
|
+
* const schema = components.schemas?.[name];
|
|
240
|
+
* console.log(`Processing schema: ${name}`);
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
41
244
|
toSchemasRefNames() {
|
|
42
245
|
return Object.keys(__classPrivateFieldGet(this, _OasComponents_fields, "f").schemas ?? {});
|
|
43
246
|
}
|
|
@@ -45,6 +248,42 @@ export class OasComponents {
|
|
|
45
248
|
get schemas() {
|
|
46
249
|
return __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas;
|
|
47
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Removes a schema from the components and returns it.
|
|
253
|
+
*
|
|
254
|
+
* This method permanently removes a schema from the components object
|
|
255
|
+
* and returns the removed schema. This is useful during processing when
|
|
256
|
+
* you need to extract and handle specific schemas separately.
|
|
257
|
+
*
|
|
258
|
+
* @param refName - The reference name of the schema to remove
|
|
259
|
+
* @returns The removed schema object or reference
|
|
260
|
+
*
|
|
261
|
+
* @throws {Error} When the schema doesn't exist or schemas object is undefined
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const components = new OasComponents({
|
|
266
|
+
* schemas: {
|
|
267
|
+
* User: userSchema,
|
|
268
|
+
* Product: productSchema,
|
|
269
|
+
* Internal: internalSchema
|
|
270
|
+
* }
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* // Remove internal schema that shouldn't be exposed
|
|
274
|
+
* const internalSchema = components.removeSchema('Internal');
|
|
275
|
+
* console.log('Removed internal schema');
|
|
276
|
+
*
|
|
277
|
+
* // Check remaining schemas
|
|
278
|
+
* const remainingSchemas = components.toSchemasRefNames();
|
|
279
|
+
* console.log(remainingSchemas); // ['User', 'Product']
|
|
280
|
+
*
|
|
281
|
+
* // Process removed schema separately
|
|
282
|
+
* if (!internalSchema.isRef()) {
|
|
283
|
+
* console.log('Processing internal schema privately');
|
|
284
|
+
* }
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
48
287
|
removeSchema(refName) {
|
|
49
288
|
const { [refName]: removed, ...rest } = __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas;
|
|
50
289
|
__classPrivateFieldGet(this, _OasComponents_fields, "f").schemas = rest;
|