@skmtc/core 0.0.808 → 0.0.810
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/types.d.ts +0 -8
- package/esm/context/types.d.ts.map +1 -1
- package/esm/dsl/model/toModelBase.d.ts +24 -2
- package/esm/dsl/model/toModelBase.d.ts.map +1 -1
- package/esm/dsl/model/types.d.ts +2 -2
- package/esm/dsl/operation/toOperationBase.d.ts +26 -3
- package/esm/dsl/operation/toOperationBase.d.ts.map +1 -1
- package/esm/dsl/operation/types.d.ts +2 -2
- package/esm/oas/array/array-types.d.ts +238 -25
- package/esm/oas/array/array-types.d.ts.map +1 -1
- package/esm/oas/array/array-types.js +97 -5
- package/esm/oas/boolean/boolean-types.d.ts +81 -9
- package/esm/oas/boolean/boolean-types.d.ts.map +1 -1
- package/esm/oas/boolean/boolean-types.js +32 -2
- package/esm/oas/contact/contact-types.d.ts +176 -0
- package/esm/oas/contact/contact-types.d.ts.map +1 -1
- package/esm/oas/contact/contact-types.js +102 -0
- package/esm/oas/header/Header.d.ts +8 -185
- package/esm/oas/header/Header.d.ts.map +1 -1
- package/esm/oas/header/Header.js +57 -220
- package/esm/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
- package/esm/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
- package/esm/oas/mediaType/toMediaTypeItemV3.js +272 -0
- package/esm/oas/operation/operation-types.d.ts +251 -0
- package/esm/oas/operation/operation-types.d.ts.map +1 -1
- package/esm/oas/operation/operation-types.js +98 -0
- package/esm/oas/string/string-types.d.ts +192 -18
- package/esm/oas/string/string-types.d.ts.map +1 -1
- package/esm/oas/string/string-types.js +76 -4
- package/esm/types/ModuleExport.d.ts +130 -0
- package/esm/types/ModuleExport.d.ts.map +1 -1
- package/esm/types/ModuleExport.js +36 -0
- package/esm/typescript/List.d.ts +2 -2
- package/esm/typescript/List.d.ts.map +1 -1
- package/esm/typescript/List.js +4 -4
- package/esm/typescript/toPathTemplate.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/context/types.d.ts +0 -8
- package/script/context/types.d.ts.map +1 -1
- package/script/dsl/model/toModelBase.d.ts +24 -2
- package/script/dsl/model/toModelBase.d.ts.map +1 -1
- package/script/dsl/model/types.d.ts +2 -2
- package/script/dsl/operation/toOperationBase.d.ts +26 -3
- package/script/dsl/operation/toOperationBase.d.ts.map +1 -1
- package/script/dsl/operation/types.d.ts +2 -2
- package/script/oas/array/array-types.d.ts +238 -25
- package/script/oas/array/array-types.d.ts.map +1 -1
- package/script/oas/array/array-types.js +97 -5
- package/script/oas/boolean/boolean-types.d.ts +81 -9
- package/script/oas/boolean/boolean-types.d.ts.map +1 -1
- package/script/oas/boolean/boolean-types.js +32 -2
- package/script/oas/contact/contact-types.d.ts +176 -0
- package/script/oas/contact/contact-types.d.ts.map +1 -1
- package/script/oas/contact/contact-types.js +102 -0
- package/script/oas/header/Header.d.ts +8 -185
- package/script/oas/header/Header.d.ts.map +1 -1
- package/script/oas/header/Header.js +57 -220
- package/script/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
- package/script/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
- package/script/oas/mediaType/toMediaTypeItemV3.js +272 -0
- package/script/oas/operation/operation-types.d.ts +251 -0
- package/script/oas/operation/operation-types.d.ts.map +1 -1
- package/script/oas/operation/operation-types.js +98 -0
- package/script/oas/string/string-types.d.ts +192 -18
- package/script/oas/string/string-types.d.ts.map +1 -1
- package/script/oas/string/string-types.js +76 -4
- package/script/types/ModuleExport.d.ts +130 -0
- package/script/types/ModuleExport.d.ts.map +1 -1
- package/script/types/ModuleExport.js +36 -0
- package/script/typescript/List.d.ts +2 -2
- package/script/typescript/List.d.ts.map +1 -1
- package/script/typescript/List.js +4 -4
- package/script/typescript/toPathTemplate.d.ts.map +1 -1
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _OasHeader_fields;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.OasHeader = void 0;
|
|
16
4
|
/**
|
|
@@ -24,15 +12,6 @@ exports.OasHeader = void 0;
|
|
|
24
12
|
* This class provides comprehensive support for header definitions with typed
|
|
25
13
|
* values, validation schemas, examples, and documentation.
|
|
26
14
|
*
|
|
27
|
-
* ## Key Features
|
|
28
|
-
*
|
|
29
|
-
* - **Schema Validation**: Typed header values through schema definitions
|
|
30
|
-
* - **Examples**: Multiple example values for documentation and testing
|
|
31
|
-
* - **Content Types**: Support for complex header values with media types
|
|
32
|
-
* - **Deprecation Support**: Mark headers as deprecated with proper warnings
|
|
33
|
-
* - **Required/Optional**: Control whether headers are mandatory
|
|
34
|
-
* - **Documentation**: Rich description support for API documentation
|
|
35
|
-
*
|
|
36
15
|
* @example Basic authentication header
|
|
37
16
|
* ```typescript
|
|
38
17
|
* import { OasHeader, OasString } from '@skmtc/core';
|
|
@@ -52,173 +31,6 @@ exports.OasHeader = void 0;
|
|
|
52
31
|
* }
|
|
53
32
|
* });
|
|
54
33
|
* ```
|
|
55
|
-
*
|
|
56
|
-
* @example Pagination headers
|
|
57
|
-
* ```typescript
|
|
58
|
-
* const totalCountHeader = new OasHeader({
|
|
59
|
-
* description: 'Total number of items available',
|
|
60
|
-
* required: false,
|
|
61
|
-
* schema: new OasInteger({
|
|
62
|
-
* minimum: 0,
|
|
63
|
-
* description: 'Non-negative integer count'
|
|
64
|
-
* }),
|
|
65
|
-
* examples: {
|
|
66
|
-
* empty: new OasExample({ value: 0, description: 'No items' }),
|
|
67
|
-
* normal: new OasExample({ value: 150, description: 'Normal case' }),
|
|
68
|
-
* large: new OasExample({ value: 10000, description: 'Large dataset' })
|
|
69
|
-
* }
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* const linkHeader = new OasHeader({
|
|
73
|
-
* description: 'Pagination links (RFC 5988)',
|
|
74
|
-
* required: false,
|
|
75
|
-
* schema: new OasString({
|
|
76
|
-
* description: 'Comma-separated list of link relations'
|
|
77
|
-
* }),
|
|
78
|
-
* examples: {
|
|
79
|
-
* withNext: new OasExample({
|
|
80
|
-
* value: '</api/users?page=2>; rel="next", </api/users?page=10>; rel="last"'
|
|
81
|
-
* }),
|
|
82
|
-
* lastPage: new OasExample({
|
|
83
|
-
* value: '</api/users?page=9>; rel="prev", </api/users?page=1>; rel="first"'
|
|
84
|
-
* })
|
|
85
|
-
* }
|
|
86
|
-
* });
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* @example Content type and encoding headers
|
|
90
|
-
* ```typescript
|
|
91
|
-
* const contentTypeHeader = new OasHeader({
|
|
92
|
-
* description: 'MIME type of the response content',
|
|
93
|
-
* required: true,
|
|
94
|
-
* schema: new OasString({
|
|
95
|
-
* enum: [
|
|
96
|
-
* 'application/json',
|
|
97
|
-
* 'application/xml',
|
|
98
|
-
* 'text/csv',
|
|
99
|
-
* 'application/pdf',
|
|
100
|
-
* 'application/octet-stream'
|
|
101
|
-
* ]
|
|
102
|
-
* }),
|
|
103
|
-
* examples: {
|
|
104
|
-
* json: new OasExample({ value: 'application/json' }),
|
|
105
|
-
* xml: new OasExample({ value: 'application/xml' }),
|
|
106
|
-
* csv: new OasExample({ value: 'text/csv' })
|
|
107
|
-
* }
|
|
108
|
-
* });
|
|
109
|
-
*
|
|
110
|
-
* const contentLengthHeader = new OasHeader({
|
|
111
|
-
* description: 'Size of the response body in bytes',
|
|
112
|
-
* required: false,
|
|
113
|
-
* schema: new OasInteger({
|
|
114
|
-
* minimum: 0,
|
|
115
|
-
* description: 'Content size in bytes'
|
|
116
|
-
* })
|
|
117
|
-
* });
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* @example Rate limiting headers
|
|
121
|
-
* ```typescript
|
|
122
|
-
* const rateLimitHeader = new OasHeader({
|
|
123
|
-
* description: 'Number of requests remaining in the current window',
|
|
124
|
-
* required: false,
|
|
125
|
-
* schema: new OasInteger({
|
|
126
|
-
* minimum: 0,
|
|
127
|
-
* description: 'Remaining request count'
|
|
128
|
-
* }),
|
|
129
|
-
* examples: {
|
|
130
|
-
* available: new OasExample({ value: 95, description: '95 requests remaining' }),
|
|
131
|
-
* depleted: new OasExample({ value: 0, description: 'Rate limit reached' })
|
|
132
|
-
* }
|
|
133
|
-
* });
|
|
134
|
-
*
|
|
135
|
-
* const rateLimitResetHeader = new OasHeader({
|
|
136
|
-
* description: 'Unix timestamp when the rate limit window resets',
|
|
137
|
-
* required: false,
|
|
138
|
-
* schema: new OasInteger({
|
|
139
|
-
* minimum: 0,
|
|
140
|
-
* description: 'Unix timestamp in seconds'
|
|
141
|
-
* }),
|
|
142
|
-
* examples: {
|
|
143
|
-
* reset: new OasExample({
|
|
144
|
-
* value: 1634567890,
|
|
145
|
-
* description: 'Reset at 2021-10-18 12:31:30 UTC'
|
|
146
|
-
* })
|
|
147
|
-
* }
|
|
148
|
-
* });
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* @example Custom application headers
|
|
152
|
-
* ```typescript
|
|
153
|
-
* const requestIdHeader = new OasHeader({
|
|
154
|
-
* description: 'Unique identifier for request tracing',
|
|
155
|
-
* required: false,
|
|
156
|
-
* schema: new OasString({
|
|
157
|
-
* format: 'uuid',
|
|
158
|
-
* description: 'UUID v4 request identifier'
|
|
159
|
-
* }),
|
|
160
|
-
* examples: {
|
|
161
|
-
* uuid: new OasExample({
|
|
162
|
-
* value: '123e4567-e89b-12d3-a456-426614174000',
|
|
163
|
-
* description: 'Request tracking ID'
|
|
164
|
-
* })
|
|
165
|
-
* }
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* const serverTimingHeader = new OasHeader({
|
|
169
|
-
* description: 'Server-side performance metrics',
|
|
170
|
-
* required: false,
|
|
171
|
-
* schema: new OasString({
|
|
172
|
-
* description: 'Server-Timing header format (RFC 8760)'
|
|
173
|
-
* }),
|
|
174
|
-
* examples: {
|
|
175
|
-
* timing: new OasExample({
|
|
176
|
-
* value: 'db;dur=53, app;dur=47.2',
|
|
177
|
-
* description: 'Database took 53ms, app logic 47.2ms'
|
|
178
|
-
* })
|
|
179
|
-
* }
|
|
180
|
-
* });
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* @example Deprecated header
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const deprecatedHeader = new OasHeader({
|
|
186
|
-
* description: 'Legacy API version header (deprecated)',
|
|
187
|
-
* required: false,
|
|
188
|
-
* deprecated: true,
|
|
189
|
-
* schema: new OasString({
|
|
190
|
-
* enum: ['v1', 'v2'],
|
|
191
|
-
* description: 'Use Accept or Content-Type header instead'
|
|
192
|
-
* }),
|
|
193
|
-
* examples: {
|
|
194
|
-
* legacy: new OasExample({
|
|
195
|
-
* value: 'v1',
|
|
196
|
-
* description: 'Legacy version (use Accept header instead)'
|
|
197
|
-
* })
|
|
198
|
-
* }
|
|
199
|
-
* });
|
|
200
|
-
* ```
|
|
201
|
-
*
|
|
202
|
-
* @example Using in response definitions
|
|
203
|
-
* ```typescript
|
|
204
|
-
* const successResponse = new OasResponse({
|
|
205
|
-
* description: 'Paginated user list',
|
|
206
|
-
* headers: {
|
|
207
|
-
* 'X-Total-Count': totalCountHeader,
|
|
208
|
-
* 'Link': linkHeader,
|
|
209
|
-
* 'X-Rate-Limit-Remaining': rateLimitHeader,
|
|
210
|
-
* 'X-Rate-Limit-Reset': rateLimitResetHeader,
|
|
211
|
-
* 'X-Request-ID': requestIdHeader
|
|
212
|
-
* },
|
|
213
|
-
* content: {
|
|
214
|
-
* 'application/json': new OasMediaType({
|
|
215
|
-
* schema: new OasArray({
|
|
216
|
-
* items: new OasRef({ $ref: '#/components/schemas/User' })
|
|
217
|
-
* })
|
|
218
|
-
* })
|
|
219
|
-
* }
|
|
220
|
-
* });
|
|
221
|
-
* ```
|
|
222
34
|
*/
|
|
223
35
|
class OasHeader {
|
|
224
36
|
constructor(fields) {
|
|
@@ -228,36 +40,62 @@ class OasHeader {
|
|
|
228
40
|
writable: true,
|
|
229
41
|
value: 'header'
|
|
230
42
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
43
|
+
/** Brief description of header */
|
|
44
|
+
Object.defineProperty(this, "description", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: void 0
|
|
49
|
+
});
|
|
50
|
+
/** Indicates if header is mandatory. Default value is `false` */
|
|
51
|
+
Object.defineProperty(this, "required", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
/** Indicates if header is deprecated and should no longer be used. Default value is false */
|
|
58
|
+
Object.defineProperty(this, "deprecated", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: void 0
|
|
63
|
+
});
|
|
64
|
+
/** Schema for the header */
|
|
65
|
+
Object.defineProperty(this, "schema", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
/** Examples of the header */
|
|
72
|
+
Object.defineProperty(this, "examples", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
78
|
+
/** Content of the header */
|
|
79
|
+
Object.defineProperty(this, "content", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
/** Specification Extension fields */
|
|
86
|
+
Object.defineProperty(this, "extensionFields", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: void 0
|
|
91
|
+
});
|
|
92
|
+
this.description = fields.description;
|
|
93
|
+
this.required = fields.required;
|
|
94
|
+
this.deprecated = fields.deprecated;
|
|
95
|
+
this.schema = fields.schema;
|
|
96
|
+
this.examples = fields.examples;
|
|
97
|
+
this.content = fields.content;
|
|
98
|
+
this.extensionFields = fields.extensionFields;
|
|
261
99
|
}
|
|
262
100
|
/** Returns true if object is a reference */
|
|
263
101
|
isRef() {
|
|
@@ -279,7 +117,7 @@ class OasHeader {
|
|
|
279
117
|
if (this.schema) {
|
|
280
118
|
return this.schema;
|
|
281
119
|
}
|
|
282
|
-
const schema =
|
|
120
|
+
const schema = this.content?.[mediaType]?.schema;
|
|
283
121
|
if (!schema) {
|
|
284
122
|
throw new Error(`Schema not found for media type ${mediaType}`);
|
|
285
123
|
}
|
|
@@ -296,4 +134,3 @@ class OasHeader {
|
|
|
296
134
|
}
|
|
297
135
|
}
|
|
298
136
|
exports.OasHeader = OasHeader;
|
|
299
|
-
_OasHeader_fields = new WeakMap();
|
|
@@ -1,21 +1,309 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import type { ParseContext } from '../../context/ParseContext.js';
|
|
3
3
|
import { OasMediaType } from './MediaType.js';
|
|
4
|
+
/**
|
|
5
|
+
* Arguments for transforming an OpenAPI v3 media type item into an OAS media type.
|
|
6
|
+
*/
|
|
4
7
|
type ToMediaTypeItemV3Args = {
|
|
8
|
+
/** The OpenAPI v3 media type object to transform */
|
|
5
9
|
mediaTypeItem: OpenAPIV3.MediaTypeObject;
|
|
10
|
+
/** The media type string (e.g., 'application/json', 'text/plain') */
|
|
6
11
|
mediaType: string;
|
|
12
|
+
/** The parsing context for tracing and processing */
|
|
7
13
|
context: ParseContext;
|
|
8
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Transforms an OpenAPI v3 media type object into an internal OAS media type representation.
|
|
17
|
+
*
|
|
18
|
+
* This function processes OpenAPI v3 MediaType objects, extracting schema definitions,
|
|
19
|
+
* examples, encoding information, and specification extensions. It creates a structured
|
|
20
|
+
* internal representation that can be used by the SKMTC pipeline for code generation
|
|
21
|
+
* and validation.
|
|
22
|
+
*
|
|
23
|
+
* The transformation handles all standard OpenAPI v3 MediaType properties including
|
|
24
|
+
* schema references, inline schemas, examples, encoding specifications, and custom
|
|
25
|
+
* extension fields that begin with 'x-'.
|
|
26
|
+
*
|
|
27
|
+
* @param args - Transformation arguments
|
|
28
|
+
* @param args.mediaTypeItem - The OpenAPI v3 media type object to process
|
|
29
|
+
* @param args.mediaType - The media type identifier (MIME type)
|
|
30
|
+
* @param args.context - Parsing context for tracing and error handling
|
|
31
|
+
* @returns Structured OAS media type object for internal processing
|
|
32
|
+
*
|
|
33
|
+
* @example Transforming JSON media type
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { toMediaTypeItemV3 } from '@skmtc/core/oas/mediaType';
|
|
36
|
+
*
|
|
37
|
+
* const jsonMediaType = {
|
|
38
|
+
* schema: {
|
|
39
|
+
* type: 'object',
|
|
40
|
+
* properties: {
|
|
41
|
+
* name: { type: 'string' },
|
|
42
|
+
* email: { type: 'string', format: 'email' }
|
|
43
|
+
* }
|
|
44
|
+
* },
|
|
45
|
+
* example: {
|
|
46
|
+
* name: 'John Doe',
|
|
47
|
+
* email: 'john@example.com'
|
|
48
|
+
* }
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
* const result = toMediaTypeItemV3({
|
|
52
|
+
* mediaTypeItem: jsonMediaType,
|
|
53
|
+
* mediaType: 'application/json',
|
|
54
|
+
* context: parseContext
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* console.log(result.mediaType); // 'application/json'
|
|
58
|
+
* console.log(result.schema); // Processed schema object
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Processing form data with encoding
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const formMediaType = {
|
|
64
|
+
* schema: {
|
|
65
|
+
* type: 'object',
|
|
66
|
+
* properties: {
|
|
67
|
+
* file: { type: 'string', format: 'binary' },
|
|
68
|
+
* metadata: { type: 'string' }
|
|
69
|
+
* }
|
|
70
|
+
* },
|
|
71
|
+
* encoding: {
|
|
72
|
+
* file: {
|
|
73
|
+
* contentType: 'image/png',
|
|
74
|
+
* headers: {
|
|
75
|
+
* 'X-Rate-Limit': {
|
|
76
|
+
* schema: { type: 'integer' }
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* const result = toMediaTypeItemV3({
|
|
84
|
+
* mediaTypeItem: formMediaType,
|
|
85
|
+
* mediaType: 'multipart/form-data',
|
|
86
|
+
* context: parseContext
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* console.log(result.encoding); // Processed encoding configuration
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example Handling multiple examples
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const mediaTypeWithExamples = {
|
|
95
|
+
* schema: { type: 'string' },
|
|
96
|
+
* examples: {
|
|
97
|
+
* success: {
|
|
98
|
+
* summary: 'Successful response',
|
|
99
|
+
* value: 'Operation completed'
|
|
100
|
+
* },
|
|
101
|
+
* error: {
|
|
102
|
+
* summary: 'Error response',
|
|
103
|
+
* value: 'Operation failed'
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* };
|
|
107
|
+
*
|
|
108
|
+
* const result = toMediaTypeItemV3({
|
|
109
|
+
* mediaTypeItem: mediaTypeWithExamples,
|
|
110
|
+
* mediaType: 'text/plain',
|
|
111
|
+
* context: parseContext
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* console.log(Object.keys(result.examples)); // ['success', 'error']
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
9
117
|
export declare const toMediaTypeItemV3: ({ mediaTypeItem, mediaType, context }: ToMediaTypeItemV3Args) => OasMediaType;
|
|
118
|
+
/**
|
|
119
|
+
* Arguments for transforming multiple OpenAPI v3 media type items.
|
|
120
|
+
*/
|
|
10
121
|
type ToMediaTypeItemsV3Args = {
|
|
122
|
+
/** Map of media type strings to OpenAPI v3 MediaType objects */
|
|
11
123
|
content: Record<string, OpenAPIV3.MediaTypeObject>;
|
|
124
|
+
/** The parsing context for tracing and processing */
|
|
12
125
|
context: ParseContext;
|
|
13
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Transforms multiple OpenAPI v3 media type objects into internal OAS representations.
|
|
129
|
+
*
|
|
130
|
+
* This function processes a complete content map from OpenAPI v3, transforming each
|
|
131
|
+
* media type entry into its internal OAS representation. It's commonly used to process
|
|
132
|
+
* the `content` property of request bodies, responses, and parameters that support
|
|
133
|
+
* multiple media types.
|
|
134
|
+
*
|
|
135
|
+
* The function maintains the original media type keys while transforming the values
|
|
136
|
+
* into structured OAS media type objects. Each transformation is traced for debugging
|
|
137
|
+
* and error tracking purposes.
|
|
138
|
+
*
|
|
139
|
+
* @param args - Transformation arguments
|
|
140
|
+
* @param args.content - Map of media types to OpenAPI MediaType objects
|
|
141
|
+
* @param args.context - Parsing context for tracing and error handling
|
|
142
|
+
* @returns Map of media type strings to processed OAS media type objects
|
|
143
|
+
*
|
|
144
|
+
* @example Processing multiple content types
|
|
145
|
+
* ```typescript
|
|
146
|
+
* import { toMediaTypeItemsV3 } from '@skmtc/core/oas/mediaType';
|
|
147
|
+
*
|
|
148
|
+
* const content = {
|
|
149
|
+
* 'application/json': {
|
|
150
|
+
* schema: {
|
|
151
|
+
* type: 'object',
|
|
152
|
+
* properties: { message: { type: 'string' } }
|
|
153
|
+
* }
|
|
154
|
+
* },
|
|
155
|
+
* 'application/xml': {
|
|
156
|
+
* schema: {
|
|
157
|
+
* type: 'string'
|
|
158
|
+
* }
|
|
159
|
+
* },
|
|
160
|
+
* 'text/plain': {
|
|
161
|
+
* schema: {
|
|
162
|
+
* type: 'string'
|
|
163
|
+
* },
|
|
164
|
+
* example: 'Plain text response'
|
|
165
|
+
* }
|
|
166
|
+
* };
|
|
167
|
+
*
|
|
168
|
+
* const result = toMediaTypeItemsV3({
|
|
169
|
+
* content,
|
|
170
|
+
* context: parseContext
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* console.log(Object.keys(result)); // ['application/json', 'application/xml', 'text/plain']
|
|
174
|
+
* console.log(result['application/json'].mediaType); // 'application/json'
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example Processing request body content types
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const requestBodyContent = {
|
|
180
|
+
* 'application/json': {
|
|
181
|
+
* schema: { $ref: '#/components/schemas/CreateUserRequest' }
|
|
182
|
+
* },
|
|
183
|
+
* 'application/x-www-form-urlencoded': {
|
|
184
|
+
* schema: {
|
|
185
|
+
* type: 'object',
|
|
186
|
+
* properties: {
|
|
187
|
+
* name: { type: 'string' },
|
|
188
|
+
* email: { type: 'string' }
|
|
189
|
+
* }
|
|
190
|
+
* },
|
|
191
|
+
* encoding: {
|
|
192
|
+
* email: {
|
|
193
|
+
* style: 'form',
|
|
194
|
+
* explode: false
|
|
195
|
+
* }
|
|
196
|
+
* }
|
|
197
|
+
* }
|
|
198
|
+
* };
|
|
199
|
+
*
|
|
200
|
+
* const processed = toMediaTypeItemsV3({
|
|
201
|
+
* content: requestBodyContent,
|
|
202
|
+
* context: parseContext
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* // Each media type is processed with its specific configuration
|
|
206
|
+
* console.log(processed['application/json'].schema); // Reference object
|
|
207
|
+
* console.log(processed['application/x-www-form-urlencoded'].encoding); // Form encoding config
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
14
210
|
export declare const toMediaTypeItemsV3: ({ content, context }: ToMediaTypeItemsV3Args) => Record<string, OasMediaType>;
|
|
211
|
+
/**
|
|
212
|
+
* Arguments for optionally transforming OpenAPI v3 media type items.
|
|
213
|
+
*/
|
|
15
214
|
type ToOptionalMediaTypeItemsV3Args = {
|
|
215
|
+
/** Optional map of media type strings to OpenAPI v3 MediaType objects */
|
|
16
216
|
content: Record<string, OpenAPIV3.MediaTypeObject> | undefined;
|
|
217
|
+
/** The parsing context for tracing and processing */
|
|
17
218
|
context: ParseContext;
|
|
18
219
|
};
|
|
220
|
+
/**
|
|
221
|
+
* Optionally transforms OpenAPI v3 media type objects when content is provided.
|
|
222
|
+
*
|
|
223
|
+
* This function provides a safe way to process media type content that may or may not
|
|
224
|
+
* be present in the OpenAPI specification. It handles the common pattern where content
|
|
225
|
+
* properties are optional in OpenAPI objects (like responses without bodies or
|
|
226
|
+
* operations without request bodies).
|
|
227
|
+
*
|
|
228
|
+
* When content is undefined, the function returns undefined without processing.
|
|
229
|
+
* When content is provided, it delegates to `toMediaTypeItemsV3` for full processing.
|
|
230
|
+
*
|
|
231
|
+
* @param args - Transformation arguments
|
|
232
|
+
* @param args.content - Optional map of media types to OpenAPI MediaType objects
|
|
233
|
+
* @param args.context - Parsing context for tracing and error handling
|
|
234
|
+
* @returns Map of processed media types if content exists, undefined otherwise
|
|
235
|
+
*
|
|
236
|
+
* @example Handling optional response content
|
|
237
|
+
* ```typescript
|
|
238
|
+
* import { toOptionalMediaTypeItemsV3 } from '@skmtc/core/oas/mediaType';
|
|
239
|
+
*
|
|
240
|
+
* // Response with content
|
|
241
|
+
* const responseWithContent = {
|
|
242
|
+
* description: 'Successful response',
|
|
243
|
+
* content: {
|
|
244
|
+
* 'application/json': {
|
|
245
|
+
* schema: { type: 'object' }
|
|
246
|
+
* }
|
|
247
|
+
* }
|
|
248
|
+
* };
|
|
249
|
+
*
|
|
250
|
+
* const withContent = toOptionalMediaTypeItemsV3({
|
|
251
|
+
* content: responseWithContent.content,
|
|
252
|
+
* context: parseContext
|
|
253
|
+
* });
|
|
254
|
+
* console.log(withContent); // { 'application/json': OasMediaType }
|
|
255
|
+
*
|
|
256
|
+
* // Response without content (like 204 No Content)
|
|
257
|
+
* const responseNoContent = {
|
|
258
|
+
* description: 'No content response'
|
|
259
|
+
* };
|
|
260
|
+
*
|
|
261
|
+
* const noContent = toOptionalMediaTypeItemsV3({
|
|
262
|
+
* content: responseNoContent.content, // undefined
|
|
263
|
+
* context: parseContext
|
|
264
|
+
* });
|
|
265
|
+
* console.log(noContent); // undefined
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @example Processing operations with optional request bodies
|
|
269
|
+
* ```typescript
|
|
270
|
+
* function processOperation(operation: OpenAPIV3.OperationObject) {
|
|
271
|
+
* const requestBodyContent = toOptionalMediaTypeItemsV3({
|
|
272
|
+
* content: operation.requestBody?.content,
|
|
273
|
+
* context: parseContext
|
|
274
|
+
* });
|
|
275
|
+
*
|
|
276
|
+
* if (requestBodyContent) {
|
|
277
|
+
* console.log('Operation has request body with media types:');
|
|
278
|
+
* console.log(Object.keys(requestBodyContent));
|
|
279
|
+
* } else {
|
|
280
|
+
* console.log('Operation has no request body');
|
|
281
|
+
* }
|
|
282
|
+
* }
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @example Safe processing in response handlers
|
|
286
|
+
* ```typescript
|
|
287
|
+
* class ResponseProcessor {
|
|
288
|
+
* processResponse(response: OpenAPIV3.ResponseObject) {
|
|
289
|
+
* const mediaTypes = toOptionalMediaTypeItemsV3({
|
|
290
|
+
* content: response.content,
|
|
291
|
+
* context: this.context
|
|
292
|
+
* });
|
|
293
|
+
*
|
|
294
|
+
* // Safe to check without worrying about undefined content
|
|
295
|
+
* const hasJsonResponse = mediaTypes && 'application/json' in mediaTypes;
|
|
296
|
+
*
|
|
297
|
+
* if (hasJsonResponse) {
|
|
298
|
+
* const jsonMediaType = mediaTypes['application/json'];
|
|
299
|
+
* return this.generateJsonResponseHandler(jsonMediaType);
|
|
300
|
+
* }
|
|
301
|
+
*
|
|
302
|
+
* return this.generateEmptyResponseHandler();
|
|
303
|
+
* }
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
19
307
|
export declare const toOptionalMediaTypeItemsV3: ({ content, context }: ToOptionalMediaTypeItemsV3Args) => Record<string, OasMediaType> | undefined;
|
|
20
308
|
export {};
|
|
21
309
|
//# sourceMappingURL=toMediaTypeItemV3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toMediaTypeItemV3.d.ts","sourceRoot":"","sources":["../../../src/oas/mediaType/toMediaTypeItemV3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,OAAO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