@skmtc/core 0.0.807 → 0.0.809

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/oas/array/array-types.d.ts +238 -25
  2. package/esm/oas/array/array-types.d.ts.map +1 -1
  3. package/esm/oas/array/array-types.js +97 -5
  4. package/esm/oas/boolean/boolean-types.d.ts +81 -9
  5. package/esm/oas/boolean/boolean-types.d.ts.map +1 -1
  6. package/esm/oas/boolean/boolean-types.js +32 -2
  7. package/esm/oas/contact/contact-types.d.ts +176 -0
  8. package/esm/oas/contact/contact-types.d.ts.map +1 -1
  9. package/esm/oas/contact/contact-types.js +102 -0
  10. package/esm/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
  11. package/esm/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
  12. package/esm/oas/mediaType/toMediaTypeItemV3.js +272 -0
  13. package/esm/oas/operation/operation-types.d.ts +251 -0
  14. package/esm/oas/operation/operation-types.d.ts.map +1 -1
  15. package/esm/oas/operation/operation-types.js +98 -0
  16. package/esm/oas/string/string-types.d.ts +192 -18
  17. package/esm/oas/string/string-types.d.ts.map +1 -1
  18. package/esm/oas/string/string-types.js +76 -4
  19. package/esm/types/ModuleExport.d.ts +130 -0
  20. package/esm/types/ModuleExport.d.ts.map +1 -1
  21. package/esm/types/ModuleExport.js +36 -0
  22. package/esm/types/PrettierConfig.d.ts +74 -0
  23. package/esm/types/PrettierConfig.d.ts.map +1 -1
  24. package/esm/types/PrettierConfig.js +74 -0
  25. package/esm/types/Results.d.ts +97 -0
  26. package/esm/types/Results.d.ts.map +1 -1
  27. package/esm/types/Results.js +97 -0
  28. package/package.json +1 -1
  29. package/script/oas/array/array-types.d.ts +238 -25
  30. package/script/oas/array/array-types.d.ts.map +1 -1
  31. package/script/oas/array/array-types.js +97 -5
  32. package/script/oas/boolean/boolean-types.d.ts +81 -9
  33. package/script/oas/boolean/boolean-types.d.ts.map +1 -1
  34. package/script/oas/boolean/boolean-types.js +32 -2
  35. package/script/oas/contact/contact-types.d.ts +176 -0
  36. package/script/oas/contact/contact-types.d.ts.map +1 -1
  37. package/script/oas/contact/contact-types.js +102 -0
  38. package/script/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
  39. package/script/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
  40. package/script/oas/mediaType/toMediaTypeItemV3.js +272 -0
  41. package/script/oas/operation/operation-types.d.ts +251 -0
  42. package/script/oas/operation/operation-types.d.ts.map +1 -1
  43. package/script/oas/operation/operation-types.js +98 -0
  44. package/script/oas/string/string-types.d.ts +192 -18
  45. package/script/oas/string/string-types.d.ts.map +1 -1
  46. package/script/oas/string/string-types.js +76 -4
  47. package/script/types/ModuleExport.d.ts +130 -0
  48. package/script/types/ModuleExport.d.ts.map +1 -1
  49. package/script/types/ModuleExport.js +36 -0
  50. package/script/types/PrettierConfig.d.ts +74 -0
  51. package/script/types/PrettierConfig.d.ts.map +1 -1
  52. package/script/types/PrettierConfig.js +74 -0
  53. package/script/types/Results.d.ts +97 -0
  54. package/script/types/Results.d.ts.map +1 -1
  55. package/script/types/Results.js +97 -0
@@ -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,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAI7C,KAAK,qBAAqB,GAAG;IAC3B,aAAa,EAAE,SAAS,CAAC,eAAe,CAAA;IACxC,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,uCAI/B,qBAAqB,KAAG,YA0B1B,CAAA;AAED,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,CAAA;IAClD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,sBAGhC,sBAAsB,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAatD,CAAA;AAED,KAAK,8BAA8B,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,GAAG,SAAS,CAAA;IAC9D,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,sBAGxC,8BAA8B,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAMlE,CAAA"}
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,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAI7C;;GAEG;AACH,KAAK,qBAAqB,GAAG;IAC3B,oDAAoD;IACpD,aAAa,EAAE,SAAS,CAAC,eAAe,CAAA;IACxC,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AACH,eAAO,MAAM,iBAAiB,GAAI,uCAI/B,qBAAqB,KAAG,YA0B1B,CAAA;AAED;;GAEG;AACH,KAAK,sBAAsB,GAAG;IAC5B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,CAAA;IAClD,qDAAqD;IACrD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,eAAO,MAAM,kBAAkB,GAAI,sBAGhC,sBAAsB,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAatD,CAAA;AAED;;GAEG;AACH,KAAK,8BAA8B,GAAG;IACpC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,GAAG,SAAS,CAAA;IAC9D,qDAAqD;IACrD,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,eAAO,MAAM,0BAA0B,GAAI,sBAGxC,8BAA8B,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAMlE,CAAA"}
@@ -5,6 +5,108 @@ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
5
5
  const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
6
6
  const MediaType_js_1 = require("./MediaType.js");
7
7
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
8
+ /**
9
+ * Transforms an OpenAPI v3 media type object into an internal OAS media type representation.
10
+ *
11
+ * This function processes OpenAPI v3 MediaType objects, extracting schema definitions,
12
+ * examples, encoding information, and specification extensions. It creates a structured
13
+ * internal representation that can be used by the SKMTC pipeline for code generation
14
+ * and validation.
15
+ *
16
+ * The transformation handles all standard OpenAPI v3 MediaType properties including
17
+ * schema references, inline schemas, examples, encoding specifications, and custom
18
+ * extension fields that begin with 'x-'.
19
+ *
20
+ * @param args - Transformation arguments
21
+ * @param args.mediaTypeItem - The OpenAPI v3 media type object to process
22
+ * @param args.mediaType - The media type identifier (MIME type)
23
+ * @param args.context - Parsing context for tracing and error handling
24
+ * @returns Structured OAS media type object for internal processing
25
+ *
26
+ * @example Transforming JSON media type
27
+ * ```typescript
28
+ * import { toMediaTypeItemV3 } from '@skmtc/core/oas/mediaType';
29
+ *
30
+ * const jsonMediaType = {
31
+ * schema: {
32
+ * type: 'object',
33
+ * properties: {
34
+ * name: { type: 'string' },
35
+ * email: { type: 'string', format: 'email' }
36
+ * }
37
+ * },
38
+ * example: {
39
+ * name: 'John Doe',
40
+ * email: 'john@example.com'
41
+ * }
42
+ * };
43
+ *
44
+ * const result = toMediaTypeItemV3({
45
+ * mediaTypeItem: jsonMediaType,
46
+ * mediaType: 'application/json',
47
+ * context: parseContext
48
+ * });
49
+ *
50
+ * console.log(result.mediaType); // 'application/json'
51
+ * console.log(result.schema); // Processed schema object
52
+ * ```
53
+ *
54
+ * @example Processing form data with encoding
55
+ * ```typescript
56
+ * const formMediaType = {
57
+ * schema: {
58
+ * type: 'object',
59
+ * properties: {
60
+ * file: { type: 'string', format: 'binary' },
61
+ * metadata: { type: 'string' }
62
+ * }
63
+ * },
64
+ * encoding: {
65
+ * file: {
66
+ * contentType: 'image/png',
67
+ * headers: {
68
+ * 'X-Rate-Limit': {
69
+ * schema: { type: 'integer' }
70
+ * }
71
+ * }
72
+ * }
73
+ * }
74
+ * };
75
+ *
76
+ * const result = toMediaTypeItemV3({
77
+ * mediaTypeItem: formMediaType,
78
+ * mediaType: 'multipart/form-data',
79
+ * context: parseContext
80
+ * });
81
+ *
82
+ * console.log(result.encoding); // Processed encoding configuration
83
+ * ```
84
+ *
85
+ * @example Handling multiple examples
86
+ * ```typescript
87
+ * const mediaTypeWithExamples = {
88
+ * schema: { type: 'string' },
89
+ * examples: {
90
+ * success: {
91
+ * summary: 'Successful response',
92
+ * value: 'Operation completed'
93
+ * },
94
+ * error: {
95
+ * summary: 'Error response',
96
+ * value: 'Operation failed'
97
+ * }
98
+ * }
99
+ * };
100
+ *
101
+ * const result = toMediaTypeItemV3({
102
+ * mediaTypeItem: mediaTypeWithExamples,
103
+ * mediaType: 'text/plain',
104
+ * context: parseContext
105
+ * });
106
+ *
107
+ * console.log(Object.keys(result.examples)); // ['success', 'error']
108
+ * ```
109
+ */
8
110
  const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, context }) => {
9
111
  const { schema, example, examples, encoding, ...skipped } = mediaTypeItem;
10
112
  const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
@@ -28,6 +130,89 @@ const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, context }) => {
28
130
  return new MediaType_js_1.OasMediaType(fields);
29
131
  };
30
132
  exports.toMediaTypeItemV3 = toMediaTypeItemV3;
133
+ /**
134
+ * Transforms multiple OpenAPI v3 media type objects into internal OAS representations.
135
+ *
136
+ * This function processes a complete content map from OpenAPI v3, transforming each
137
+ * media type entry into its internal OAS representation. It's commonly used to process
138
+ * the `content` property of request bodies, responses, and parameters that support
139
+ * multiple media types.
140
+ *
141
+ * The function maintains the original media type keys while transforming the values
142
+ * into structured OAS media type objects. Each transformation is traced for debugging
143
+ * and error tracking purposes.
144
+ *
145
+ * @param args - Transformation arguments
146
+ * @param args.content - Map of media types to OpenAPI MediaType objects
147
+ * @param args.context - Parsing context for tracing and error handling
148
+ * @returns Map of media type strings to processed OAS media type objects
149
+ *
150
+ * @example Processing multiple content types
151
+ * ```typescript
152
+ * import { toMediaTypeItemsV3 } from '@skmtc/core/oas/mediaType';
153
+ *
154
+ * const content = {
155
+ * 'application/json': {
156
+ * schema: {
157
+ * type: 'object',
158
+ * properties: { message: { type: 'string' } }
159
+ * }
160
+ * },
161
+ * 'application/xml': {
162
+ * schema: {
163
+ * type: 'string'
164
+ * }
165
+ * },
166
+ * 'text/plain': {
167
+ * schema: {
168
+ * type: 'string'
169
+ * },
170
+ * example: 'Plain text response'
171
+ * }
172
+ * };
173
+ *
174
+ * const result = toMediaTypeItemsV3({
175
+ * content,
176
+ * context: parseContext
177
+ * });
178
+ *
179
+ * console.log(Object.keys(result)); // ['application/json', 'application/xml', 'text/plain']
180
+ * console.log(result['application/json'].mediaType); // 'application/json'
181
+ * ```
182
+ *
183
+ * @example Processing request body content types
184
+ * ```typescript
185
+ * const requestBodyContent = {
186
+ * 'application/json': {
187
+ * schema: { $ref: '#/components/schemas/CreateUserRequest' }
188
+ * },
189
+ * 'application/x-www-form-urlencoded': {
190
+ * schema: {
191
+ * type: 'object',
192
+ * properties: {
193
+ * name: { type: 'string' },
194
+ * email: { type: 'string' }
195
+ * }
196
+ * },
197
+ * encoding: {
198
+ * email: {
199
+ * style: 'form',
200
+ * explode: false
201
+ * }
202
+ * }
203
+ * }
204
+ * };
205
+ *
206
+ * const processed = toMediaTypeItemsV3({
207
+ * content: requestBodyContent,
208
+ * context: parseContext
209
+ * });
210
+ *
211
+ * // Each media type is processed with its specific configuration
212
+ * console.log(processed['application/json'].schema); // Reference object
213
+ * console.log(processed['application/x-www-form-urlencoded'].encoding); // Form encoding config
214
+ * ```
215
+ */
31
216
  const toMediaTypeItemsV3 = ({ content, context }) => {
32
217
  return Object.fromEntries(Object.entries(content).map(([mediaType, value]) => [
33
218
  mediaType,
@@ -39,6 +224,93 @@ const toMediaTypeItemsV3 = ({ content, context }) => {
39
224
  ]));
40
225
  };
41
226
  exports.toMediaTypeItemsV3 = toMediaTypeItemsV3;
227
+ /**
228
+ * Optionally transforms OpenAPI v3 media type objects when content is provided.
229
+ *
230
+ * This function provides a safe way to process media type content that may or may not
231
+ * be present in the OpenAPI specification. It handles the common pattern where content
232
+ * properties are optional in OpenAPI objects (like responses without bodies or
233
+ * operations without request bodies).
234
+ *
235
+ * When content is undefined, the function returns undefined without processing.
236
+ * When content is provided, it delegates to `toMediaTypeItemsV3` for full processing.
237
+ *
238
+ * @param args - Transformation arguments
239
+ * @param args.content - Optional map of media types to OpenAPI MediaType objects
240
+ * @param args.context - Parsing context for tracing and error handling
241
+ * @returns Map of processed media types if content exists, undefined otherwise
242
+ *
243
+ * @example Handling optional response content
244
+ * ```typescript
245
+ * import { toOptionalMediaTypeItemsV3 } from '@skmtc/core/oas/mediaType';
246
+ *
247
+ * // Response with content
248
+ * const responseWithContent = {
249
+ * description: 'Successful response',
250
+ * content: {
251
+ * 'application/json': {
252
+ * schema: { type: 'object' }
253
+ * }
254
+ * }
255
+ * };
256
+ *
257
+ * const withContent = toOptionalMediaTypeItemsV3({
258
+ * content: responseWithContent.content,
259
+ * context: parseContext
260
+ * });
261
+ * console.log(withContent); // { 'application/json': OasMediaType }
262
+ *
263
+ * // Response without content (like 204 No Content)
264
+ * const responseNoContent = {
265
+ * description: 'No content response'
266
+ * };
267
+ *
268
+ * const noContent = toOptionalMediaTypeItemsV3({
269
+ * content: responseNoContent.content, // undefined
270
+ * context: parseContext
271
+ * });
272
+ * console.log(noContent); // undefined
273
+ * ```
274
+ *
275
+ * @example Processing operations with optional request bodies
276
+ * ```typescript
277
+ * function processOperation(operation: OpenAPIV3.OperationObject) {
278
+ * const requestBodyContent = toOptionalMediaTypeItemsV3({
279
+ * content: operation.requestBody?.content,
280
+ * context: parseContext
281
+ * });
282
+ *
283
+ * if (requestBodyContent) {
284
+ * console.log('Operation has request body with media types:');
285
+ * console.log(Object.keys(requestBodyContent));
286
+ * } else {
287
+ * console.log('Operation has no request body');
288
+ * }
289
+ * }
290
+ * ```
291
+ *
292
+ * @example Safe processing in response handlers
293
+ * ```typescript
294
+ * class ResponseProcessor {
295
+ * processResponse(response: OpenAPIV3.ResponseObject) {
296
+ * const mediaTypes = toOptionalMediaTypeItemsV3({
297
+ * content: response.content,
298
+ * context: this.context
299
+ * });
300
+ *
301
+ * // Safe to check without worrying about undefined content
302
+ * const hasJsonResponse = mediaTypes && 'application/json' in mediaTypes;
303
+ *
304
+ * if (hasJsonResponse) {
305
+ * const jsonMediaType = mediaTypes['application/json'];
306
+ * return this.generateJsonResponseHandler(jsonMediaType);
307
+ * }
308
+ *
309
+ * return this.generateEmptyResponseHandler();
310
+ * }
311
+ * }
312
+ * ```
313
+ */
42
314
  const toOptionalMediaTypeItemsV3 = ({ content, context }) => {
43
315
  if (!content) {
44
316
  return;