@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refFns.d.ts","sourceRoot":"","sources":["../../src/helpers/refFns.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,OASxC,CAAA;AAED,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAM/C,CAAA;AAED,eAAO,MAAM,QAAQ,GAClB,aAAa,SAAS,CAAC,QAAQ,MAC/B,UAAU,eAAe,KAAG,SAAS,CAAC,YActC,CAAA"}
|
|
1
|
+
{"version":3,"file":"refFns.d.ts","sourceRoot":"","sources":["../../src/helpers/refFns.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,OASxC,CAAA;AAED;;GAEG;AACH,KAAK,GAAG,GAAG;IACT,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAM/C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,eAAO,MAAM,QAAQ,GAClB,aAAa,SAAS,CAAC,QAAQ,MAC/B,UAAU,eAAe,KAAG,SAAS,CAAC,YActC,CAAA"}
|
package/script/helpers/refFns.js
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toGetRef = exports.isRef = exports.toRefName = void 0;
|
|
4
4
|
require("../_dnt.polyfills.js");
|
|
5
|
+
/**
|
|
6
|
+
* Extracts a reference name from an OpenAPI $ref string.
|
|
7
|
+
*
|
|
8
|
+
* This function parses JSON Pointer references (like '#/components/schemas/User')
|
|
9
|
+
* and extracts the final component as a branded RefName type. It's used throughout
|
|
10
|
+
* the SKMTC system to convert string references into type-safe reference names.
|
|
11
|
+
*
|
|
12
|
+
* @param $ref - The OpenAPI reference string (e.g., '#/components/schemas/User')
|
|
13
|
+
* @returns The extracted reference name as a branded RefName type
|
|
14
|
+
*
|
|
15
|
+
* @throws {Error} When the reference string is invalid or empty
|
|
16
|
+
*
|
|
17
|
+
* @example Basic usage
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { toRefName } from '@skmtc/core/helpers';
|
|
20
|
+
*
|
|
21
|
+
* const refName = toRefName('#/components/schemas/User');
|
|
22
|
+
* console.log(refName); // 'User' (typed as RefName)
|
|
23
|
+
*
|
|
24
|
+
* const responseRef = toRefName('#/components/responses/ErrorResponse');
|
|
25
|
+
* console.log(responseRef); // 'ErrorResponse' (typed as RefName)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Error cases
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // These will throw errors:
|
|
31
|
+
* toRefName('invalid/ref/'); // Error: 'Invalid reference'
|
|
32
|
+
* toRefName('#/components/schemas/'); // Error: 'Invalid reference'
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Integration with OAS processing
|
|
36
|
+
* ```typescript
|
|
37
|
+
* class SchemaProcessor {
|
|
38
|
+
* processReference(ref: string) {
|
|
39
|
+
* const refName = toRefName(ref);
|
|
40
|
+
* const schema = this.document.components.schemas[refName];
|
|
41
|
+
* return this.processSchema(schema, refName);
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
5
46
|
const toRefName = ($ref) => {
|
|
6
47
|
// TODO: Add validation here to ensure reference exists
|
|
7
48
|
const refName = $ref.split('/').slice(-1)[0];
|
|
@@ -11,6 +52,57 @@ const toRefName = ($ref) => {
|
|
|
11
52
|
return refName;
|
|
12
53
|
};
|
|
13
54
|
exports.toRefName = toRefName;
|
|
55
|
+
/**
|
|
56
|
+
* Type guard function to check if a value is an OpenAPI reference object.
|
|
57
|
+
*
|
|
58
|
+
* This function performs runtime type checking to determine if an unknown value
|
|
59
|
+
* is an OpenAPI Reference Object (contains a $ref property with a string value).
|
|
60
|
+
* It's essential for safely handling mixed schema/reference data during processing.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The value to check for reference properties
|
|
63
|
+
* @returns True if the value is a reference object, false otherwise
|
|
64
|
+
*
|
|
65
|
+
* @example Basic type checking
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { isRef } from '@skmtc/core/helpers';
|
|
68
|
+
*
|
|
69
|
+
* const schemaOrRef: unknown = { $ref: '#/components/schemas/User' };
|
|
70
|
+
*
|
|
71
|
+
* if (isRef(schemaOrRef)) {
|
|
72
|
+
* // TypeScript now knows schemaOrRef has a $ref property
|
|
73
|
+
* console.log(schemaOrRef.$ref); // Safe to access
|
|
74
|
+
* const refName = toRefName(schemaOrRef.$ref);
|
|
75
|
+
* } else {
|
|
76
|
+
* // Handle as actual schema object
|
|
77
|
+
* console.log('Direct schema object');
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Processing mixed data
|
|
82
|
+
* ```typescript
|
|
83
|
+
* function processSchemaOrRef(data: unknown) {
|
|
84
|
+
* if (isRef(data)) {
|
|
85
|
+
* // Handle reference
|
|
86
|
+
* return resolveReference(data.$ref);
|
|
87
|
+
* } else {
|
|
88
|
+
* // Handle direct schema
|
|
89
|
+
* return processSchema(data as SchemaObject);
|
|
90
|
+
* }
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example Array processing
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const mixedArray: unknown[] = [
|
|
97
|
+
* { type: 'string' },
|
|
98
|
+
* { $ref: '#/components/schemas/User' },
|
|
99
|
+
* { type: 'number' }
|
|
100
|
+
* ];
|
|
101
|
+
*
|
|
102
|
+
* const references = mixedArray.filter(isRef);
|
|
103
|
+
* const schemas = mixedArray.filter(item => !isRef(item));
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
14
106
|
const isRef = (value) => {
|
|
15
107
|
if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {
|
|
16
108
|
return true;
|
|
@@ -20,6 +112,70 @@ const isRef = (value) => {
|
|
|
20
112
|
}
|
|
21
113
|
};
|
|
22
114
|
exports.isRef = isRef;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a reference resolver function for an OpenAPI document.
|
|
117
|
+
*
|
|
118
|
+
* This higher-order function returns a resolver that can dereference OpenAPI
|
|
119
|
+
* JSON Pointer references within the context of a specific document. It handles
|
|
120
|
+
* nested references by recursively resolving reference chains until it reaches
|
|
121
|
+
* an actual schema object.
|
|
122
|
+
*
|
|
123
|
+
* The resolver is particularly useful during schema processing where you need
|
|
124
|
+
* to follow reference chains to get the actual schema definitions.
|
|
125
|
+
*
|
|
126
|
+
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
127
|
+
* @returns A function that resolves reference objects to schema objects
|
|
128
|
+
*
|
|
129
|
+
* @throws {Error} When a reference cannot be resolved or points to a non-existent schema
|
|
130
|
+
*
|
|
131
|
+
* @example Basic usage
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import { toGetRef } from '@skmtc/core/helpers';
|
|
134
|
+
*
|
|
135
|
+
* const resolver = toGetRef(openApiDocument);
|
|
136
|
+
*
|
|
137
|
+
* const userSchema = resolver({ $ref: '#/components/schemas/User' });
|
|
138
|
+
* console.log(userSchema.type); // 'object'
|
|
139
|
+
* console.log(userSchema.properties); // User properties
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example Resolving nested references
|
|
143
|
+
* ```typescript
|
|
144
|
+
* // If User references Address, and Address references Country
|
|
145
|
+
* const resolver = toGetRef(document);
|
|
146
|
+
*
|
|
147
|
+
* // This will follow the chain: User -> Address -> Country
|
|
148
|
+
* const resolvedSchema = resolver({ $ref: '#/components/schemas/User' });
|
|
149
|
+
* // Returns the final resolved schema object
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @example Error handling
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const resolver = toGetRef(document);
|
|
155
|
+
*
|
|
156
|
+
* try {
|
|
157
|
+
* const schema = resolver({ $ref: '#/components/schemas/NonExistent' });
|
|
158
|
+
* } catch (error) {
|
|
159
|
+
* console.error('Reference resolution failed:', error.message);
|
|
160
|
+
* // Error: Invalid reference: #/components/schemas/NonExistent
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @example Integration with schema processing
|
|
165
|
+
* ```typescript
|
|
166
|
+
* class SchemaProcessor {
|
|
167
|
+
* private resolver = toGetRef(this.document);
|
|
168
|
+
*
|
|
169
|
+
* processProperty(property: SchemaObject | ReferenceObject) {
|
|
170
|
+
* if (isRef(property)) {
|
|
171
|
+
* const resolved = this.resolver(property);
|
|
172
|
+
* return this.processSchema(resolved);
|
|
173
|
+
* }
|
|
174
|
+
* return this.processSchema(property);
|
|
175
|
+
* }
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
23
179
|
const toGetRef = (oasDocument) => ({ $ref }) => {
|
|
24
180
|
const refName = (0, exports.toRefName)($ref);
|
|
25
181
|
const item = oasDocument.components?.schemas?.[refName];
|
|
@@ -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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