@skmtc/core 0.0.795 → 0.0.797

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 (61) hide show
  1. package/esm/app/validate.d.ts +32 -0
  2. package/esm/app/validate.d.ts.map +1 -1
  3. package/esm/app/validate.js +32 -0
  4. package/esm/context/CoreContext.d.ts +137 -1
  5. package/esm/context/CoreContext.d.ts.map +1 -1
  6. package/esm/context/CoreContext.js +87 -0
  7. package/esm/context/ResultsHandler.d.ts +152 -0
  8. package/esm/context/ResultsHandler.d.ts.map +1 -1
  9. package/esm/context/ResultsHandler.js +166 -1
  10. package/esm/dsl/constants.d.ts +28 -0
  11. package/esm/dsl/constants.d.ts.map +1 -1
  12. package/esm/dsl/constants.js +28 -0
  13. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  14. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  15. package/esm/oas/_helpers/parseDefault.js +128 -0
  16. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  17. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseEnum.js +104 -0
  19. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  20. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseExample.js +87 -0
  22. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  23. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseFormat.js +138 -0
  25. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  26. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  27. package/esm/oas/_helpers/parseNullable.js +113 -0
  28. package/esm/run/toV3JsonDocument.d.ts +90 -0
  29. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  30. package/esm/run/toV3JsonDocument.js +84 -0
  31. package/package.json +1 -1
  32. package/script/app/validate.d.ts +32 -0
  33. package/script/app/validate.d.ts.map +1 -1
  34. package/script/app/validate.js +32 -0
  35. package/script/context/CoreContext.d.ts +137 -1
  36. package/script/context/CoreContext.d.ts.map +1 -1
  37. package/script/context/CoreContext.js +87 -0
  38. package/script/context/ResultsHandler.d.ts +152 -0
  39. package/script/context/ResultsHandler.d.ts.map +1 -1
  40. package/script/context/ResultsHandler.js +166 -1
  41. package/script/dsl/constants.d.ts +28 -0
  42. package/script/dsl/constants.d.ts.map +1 -1
  43. package/script/dsl/constants.js +28 -0
  44. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  45. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  46. package/script/oas/_helpers/parseDefault.js +128 -0
  47. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  48. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  49. package/script/oas/_helpers/parseEnum.js +104 -0
  50. package/script/oas/_helpers/parseExample.d.ts +107 -0
  51. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  52. package/script/oas/_helpers/parseExample.js +87 -0
  53. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  54. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  55. package/script/oas/_helpers/parseFormat.js +138 -0
  56. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  57. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  58. package/script/oas/_helpers/parseNullable.js +113 -0
  59. package/script/run/toV3JsonDocument.d.ts +90 -0
  60. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  61. package/script/run/toV3JsonDocument.js +84 -0
@@ -35,6 +35,144 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseFormat = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates OpenAPI schema format values with type safety.
40
+ *
41
+ * This function extracts and validates format specifiers from OpenAPI schema objects,
42
+ * ensuring they conform to expected format types for the given schema. Invalid format
43
+ * values are removed and logged as warnings through the parse context.
44
+ *
45
+ * The format property provides additional semantic information about the expected
46
+ * structure of string values (like 'email', 'date-time', 'uuid', etc.) and numeric
47
+ * precision (like 'float', 'double' for numbers, 'int32', 'int64' for integers).
48
+ *
49
+ * @template T - The expected type of the format value (usually string)
50
+ * @template Value - The OpenAPI schema object type
51
+ *
52
+ * @param args - Parsing configuration
53
+ * @returns Parsed format data with the validated format and cleaned schema
54
+ *
55
+ * @example String format parsing
56
+ * ```typescript
57
+ * import { parseFormat } from '@skmtc/core/oas/_helpers';
58
+ * import * as v from 'valibot';
59
+ *
60
+ * const result = parseFormat({
61
+ * value: {
62
+ * type: 'string',
63
+ * format: 'email',
64
+ * maxLength: 100
65
+ * },
66
+ * valibotSchema: v.string(),
67
+ * context: parseContext
68
+ * });
69
+ *
70
+ * console.log(result.format); // 'email'
71
+ * console.log(result.value); // { type: 'string', maxLength: 100 }
72
+ * ```
73
+ *
74
+ * @example Date-time format
75
+ * ```typescript
76
+ * const result = parseFormat({
77
+ * value: {
78
+ * type: 'string',
79
+ * format: 'date-time',
80
+ * description: 'ISO 8601 timestamp'
81
+ * },
82
+ * valibotSchema: v.string(),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.format); // 'date-time'
87
+ * // Can be used to generate Date objects in TypeScript
88
+ * ```
89
+ *
90
+ * @example Number precision formats
91
+ * ```typescript
92
+ * const result = parseFormat({
93
+ * value: {
94
+ * type: 'number',
95
+ * format: 'float',
96
+ * minimum: 0
97
+ * },
98
+ * valibotSchema: v.string(), // Format is always a string
99
+ * context: parseContext
100
+ * });
101
+ *
102
+ * console.log(result.format); // 'float'
103
+ * // Indicates single-precision floating-point
104
+ * ```
105
+ *
106
+ * @example Integer format specifiers
107
+ * ```typescript
108
+ * const result = parseFormat({
109
+ * value: {
110
+ * type: 'integer',
111
+ * format: 'int64',
112
+ * description: 'Large integer ID'
113
+ * },
114
+ * valibotSchema: v.string(),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.format); // 'int64'
119
+ * // Indicates 64-bit signed integer
120
+ * ```
121
+ *
122
+ * @example Invalid format handling
123
+ * ```typescript
124
+ * const result = parseFormat({
125
+ * value: {
126
+ * type: 'string',
127
+ * format: 123, // Invalid - should be string
128
+ * pattern: '^[a-z]+$'
129
+ * } as any,
130
+ * valibotSchema: v.string(),
131
+ * context: parseContext
132
+ * });
133
+ *
134
+ * console.log(result.format); // undefined (invalid format removed)
135
+ * console.log(result.value); // { type: 'string', pattern: '^[a-z]+$' }
136
+ * // Context will log a warning about the invalid format
137
+ * ```
138
+ *
139
+ * @example Missing format (undefined)
140
+ * ```typescript
141
+ * const result = parseFormat({
142
+ * value: {
143
+ * type: 'string',
144
+ * minLength: 1,
145
+ * maxLength: 50
146
+ * },
147
+ * valibotSchema: v.string(),
148
+ * context: parseContext
149
+ * });
150
+ *
151
+ * console.log(result.format); // undefined (no format specified)
152
+ * console.log(result.value); // { type: 'string', minLength: 1, maxLength: 50 }
153
+ * ```
154
+ *
155
+ * @example Common string formats
156
+ * ```typescript
157
+ * // Standard OpenAPI string formats:
158
+ * // - 'date': full-date as defined by RFC3339
159
+ * // - 'date-time': date-time as defined by RFC3339
160
+ * // - 'time': time as defined by RFC3339
161
+ * // - 'email': email address as defined by RFC5322
162
+ * // - 'uri': URI as defined by RFC3986
163
+ * // - 'uuid': UUID as defined by RFC4122
164
+ * // - 'binary': binary data (base64 encoded)
165
+ * // - 'byte': base64 encoded characters
166
+ * // - 'password': hint for UI to obscure input
167
+ *
168
+ * const emailFormat = parseFormat({
169
+ * value: { type: 'string', format: 'email' },
170
+ * valibotSchema: v.string(),
171
+ * context
172
+ * });
173
+ * // Can generate validation: v.pipe(v.string(), v.email())
174
+ * ```
175
+ */
38
176
  const parseFormat = ({ value, valibotSchema, context }) => {
39
177
  const { format, ...rest } = value;
40
178
  const parsedFormat = context.provisionalParse({
@@ -1,12 +1,139 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContext } from '../../context/ParseContext.js';
3
+ /**
4
+ * Arguments for parsing the nullable property from OpenAPI schemas.
5
+ *
6
+ * @template Value - The OpenAPI schema object type
7
+ */
3
8
  export type ParseNullableArgs<Value extends OpenAPIV3.SchemaObject> = {
9
+ /** The OpenAPI schema object containing the nullable property */
4
10
  value: Value;
11
+ /** Parse context for error handling */
5
12
  context: ParseContext;
6
13
  };
14
+ /**
15
+ * Return type for parsed nullable data.
16
+ *
17
+ * @template Value - The OpenAPI schema object type
18
+ */
7
19
  export type ParseNullableReturn<Value extends OpenAPIV3.SchemaObject> = {
20
+ /** The validated nullable flag (true, false, or undefined) */
8
21
  nullable: boolean | undefined;
22
+ /** The schema object without the nullable property */
9
23
  value: Omit<Value, 'nullable'>;
10
24
  };
25
+ /**
26
+ * Parses and validates the nullable property from OpenAPI schema objects.
27
+ *
28
+ * This function extracts and validates the `nullable` property from OpenAPI
29
+ * schema objects, ensuring it's a valid boolean value. Invalid nullable values
30
+ * are removed and logged as warnings through the parse context.
31
+ *
32
+ * The nullable property determines whether a schema value can be null in addition
33
+ * to its primary type, which affects type generation and validation logic.
34
+ *
35
+ * @template Value - The OpenAPI schema object type
36
+ *
37
+ * @param args - Parsing configuration
38
+ * @returns Parsed nullable data with the validated flag and cleaned schema
39
+ *
40
+ * @example Valid nullable property
41
+ * ```typescript
42
+ * import { parseNullable } from '@skmtc/core/oas/_helpers';
43
+ *
44
+ * const result = parseNullable({
45
+ * value: {
46
+ * type: 'string',
47
+ * nullable: true,
48
+ * description: 'An optional string that can be null'
49
+ * },
50
+ * context: parseContext
51
+ * });
52
+ *
53
+ * console.log(result.nullable); // true
54
+ * console.log(result.value); // { type: 'string', description: 'An optional string that can be null' }
55
+ * ```
56
+ *
57
+ * @example Explicitly non-nullable
58
+ * ```typescript
59
+ * const result = parseNullable({
60
+ * value: {
61
+ * type: 'number',
62
+ * nullable: false,
63
+ * minimum: 0
64
+ * },
65
+ * context: parseContext
66
+ * });
67
+ *
68
+ * console.log(result.nullable); // false
69
+ * console.log(result.value); // { type: 'number', minimum: 0 }
70
+ * ```
71
+ *
72
+ * @example Missing nullable property (undefined)
73
+ * ```typescript
74
+ * const result = parseNullable({
75
+ * value: {
76
+ * type: 'string',
77
+ * format: 'email'
78
+ * },
79
+ * context: parseContext
80
+ * });
81
+ *
82
+ * console.log(result.nullable); // undefined (property not present)
83
+ * console.log(result.value); // { type: 'string', format: 'email' }
84
+ * ```
85
+ *
86
+ * @example Invalid nullable value
87
+ * ```typescript
88
+ * const result = parseNullable({
89
+ * value: {
90
+ * type: 'boolean',
91
+ * nullable: 'yes', // Invalid - should be boolean
92
+ * description: 'A flag'
93
+ * } as any,
94
+ * context: parseContext
95
+ * });
96
+ *
97
+ * console.log(result.nullable); // undefined (invalid value removed)
98
+ * console.log(result.value); // { type: 'boolean', description: 'A flag' }
99
+ * // Context will log a warning about the invalid nullable value
100
+ * ```
101
+ *
102
+ * @example Usage in type generation
103
+ * ```typescript
104
+ * function generateTypeScript(schema: OpenAPIV3.SchemaObject) {
105
+ * const { nullable, value } = parseNullable({ value: schema, context });
106
+ *
107
+ * const baseType = generateBaseType(value);
108
+ * const nullableType = nullable ? ` | null` : '';
109
+ *
110
+ * return `${baseType}${nullableType}`;
111
+ * }
112
+ *
113
+ * // Examples:
114
+ * // nullable: true -> 'string | null'
115
+ * // nullable: false -> 'string'
116
+ * // nullable: undefined -> 'string' (default behavior)
117
+ * ```
118
+ *
119
+ * @example Complex schema with nullable
120
+ * ```typescript
121
+ * const result = parseNullable({
122
+ * value: {
123
+ * type: 'object',
124
+ * properties: {
125
+ * name: { type: 'string' },
126
+ * age: { type: 'number' }
127
+ * },
128
+ * required: ['name'],
129
+ * nullable: true // The entire object can be null
130
+ * },
131
+ * context: parseContext
132
+ * });
133
+ *
134
+ * console.log(result.nullable); // true
135
+ * // Generated type might be: { name: string; age?: number } | null
136
+ * ```
137
+ */
11
138
  export declare const parseNullable: <Value extends OpenAPIV3.SchemaObject>({ value, context }: ParseNullableArgs<Value>) => ParseNullableReturn<Value>;
12
139
  //# sourceMappingURL=parseNullable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseNullable.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseNullable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACpE,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACtE,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,oBAGjE,iBAAiB,CAAC,KAAK,CAAC,KAAG,mBAAmB,CAAC,KAAK,CAgBtD,CAAA"}
1
+ {"version":3,"file":"parseNullable.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseNullable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACpE,iEAAiE;IACjE,KAAK,EAAE,KAAK,CAAA;IACZ,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACtE,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,sDAAsD;IACtD,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,oBAGjE,iBAAiB,CAAC,KAAK,CAAC,KAAG,mBAAmB,CAAC,KAAK,CAgBtD,CAAA"}
@@ -35,6 +35,119 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseNullable = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates the nullable property from OpenAPI schema objects.
40
+ *
41
+ * This function extracts and validates the `nullable` property from OpenAPI
42
+ * schema objects, ensuring it's a valid boolean value. Invalid nullable values
43
+ * are removed and logged as warnings through the parse context.
44
+ *
45
+ * The nullable property determines whether a schema value can be null in addition
46
+ * to its primary type, which affects type generation and validation logic.
47
+ *
48
+ * @template Value - The OpenAPI schema object type
49
+ *
50
+ * @param args - Parsing configuration
51
+ * @returns Parsed nullable data with the validated flag and cleaned schema
52
+ *
53
+ * @example Valid nullable property
54
+ * ```typescript
55
+ * import { parseNullable } from '@skmtc/core/oas/_helpers';
56
+ *
57
+ * const result = parseNullable({
58
+ * value: {
59
+ * type: 'string',
60
+ * nullable: true,
61
+ * description: 'An optional string that can be null'
62
+ * },
63
+ * context: parseContext
64
+ * });
65
+ *
66
+ * console.log(result.nullable); // true
67
+ * console.log(result.value); // { type: 'string', description: 'An optional string that can be null' }
68
+ * ```
69
+ *
70
+ * @example Explicitly non-nullable
71
+ * ```typescript
72
+ * const result = parseNullable({
73
+ * value: {
74
+ * type: 'number',
75
+ * nullable: false,
76
+ * minimum: 0
77
+ * },
78
+ * context: parseContext
79
+ * });
80
+ *
81
+ * console.log(result.nullable); // false
82
+ * console.log(result.value); // { type: 'number', minimum: 0 }
83
+ * ```
84
+ *
85
+ * @example Missing nullable property (undefined)
86
+ * ```typescript
87
+ * const result = parseNullable({
88
+ * value: {
89
+ * type: 'string',
90
+ * format: 'email'
91
+ * },
92
+ * context: parseContext
93
+ * });
94
+ *
95
+ * console.log(result.nullable); // undefined (property not present)
96
+ * console.log(result.value); // { type: 'string', format: 'email' }
97
+ * ```
98
+ *
99
+ * @example Invalid nullable value
100
+ * ```typescript
101
+ * const result = parseNullable({
102
+ * value: {
103
+ * type: 'boolean',
104
+ * nullable: 'yes', // Invalid - should be boolean
105
+ * description: 'A flag'
106
+ * } as any,
107
+ * context: parseContext
108
+ * });
109
+ *
110
+ * console.log(result.nullable); // undefined (invalid value removed)
111
+ * console.log(result.value); // { type: 'boolean', description: 'A flag' }
112
+ * // Context will log a warning about the invalid nullable value
113
+ * ```
114
+ *
115
+ * @example Usage in type generation
116
+ * ```typescript
117
+ * function generateTypeScript(schema: OpenAPIV3.SchemaObject) {
118
+ * const { nullable, value } = parseNullable({ value: schema, context });
119
+ *
120
+ * const baseType = generateBaseType(value);
121
+ * const nullableType = nullable ? ` | null` : '';
122
+ *
123
+ * return `${baseType}${nullableType}`;
124
+ * }
125
+ *
126
+ * // Examples:
127
+ * // nullable: true -> 'string | null'
128
+ * // nullable: false -> 'string'
129
+ * // nullable: undefined -> 'string' (default behavior)
130
+ * ```
131
+ *
132
+ * @example Complex schema with nullable
133
+ * ```typescript
134
+ * const result = parseNullable({
135
+ * value: {
136
+ * type: 'object',
137
+ * properties: {
138
+ * name: { type: 'string' },
139
+ * age: { type: 'number' }
140
+ * },
141
+ * required: ['name'],
142
+ * nullable: true // The entire object can be null
143
+ * },
144
+ * context: parseContext
145
+ * });
146
+ *
147
+ * console.log(result.nullable); // true
148
+ * // Generated type might be: { name: string; age?: number } | null
149
+ * ```
150
+ */
38
151
  const parseNullable = ({ value, context }) => {
39
152
  const { nullable, ...rest } = value;
40
153
  const parsedNullable = context.provisionalParse({
@@ -1,7 +1,97 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
3
+ /**
4
+ * Union type representing any supported OpenAPI document version.
5
+ *
6
+ * SKMTC supports processing OpenAPI/Swagger documents from version 2.0 through 3.1,
7
+ * automatically converting them to OpenAPI 3.0 format for internal processing.
8
+ */
3
9
  type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3_1.Document;
10
+ /**
11
+ * Parses a string into an OpenAPI document object.
12
+ *
13
+ * Automatically detects whether the input string is JSON or YAML format based on
14
+ * the content, then parses it into an OpenAPI document object. Supports all
15
+ * OpenAPI versions (2.0, 3.0.x, 3.1.x).
16
+ *
17
+ * @param schema - The OpenAPI document as a JSON or YAML string
18
+ * @returns Parsed OpenAPI document object
19
+ *
20
+ * @example Parsing JSON OpenAPI document
21
+ * ```typescript
22
+ * const jsonSchema = `{
23
+ * "openapi": "3.0.0",
24
+ * "info": { "title": "My API", "version": "1.0.0" },
25
+ * "paths": {}
26
+ * }`;
27
+ * const document = stringToSchema(jsonSchema);
28
+ * console.log(document.info.title); // "My API"
29
+ * ```
30
+ *
31
+ * @example Parsing YAML OpenAPI document
32
+ * ```typescript
33
+ * const yamlSchema = `
34
+ * openapi: 3.0.0
35
+ * info:
36
+ * title: My API
37
+ * version: 1.0.0
38
+ * paths: {}
39
+ * `;
40
+ * const document = stringToSchema(yamlSchema);
41
+ * console.log(document.info.title); // "My API"
42
+ * ```
43
+ *
44
+ * @throws {SyntaxError} If the JSON is malformed
45
+ * @throws {Error} If the YAML is malformed
46
+ */
4
47
  export declare const stringToSchema: (schema: string) => AnyOasDocument;
48
+ /**
49
+ * Converts any OpenAPI document version to OpenAPI 3.0 format.
50
+ *
51
+ * SKMTC processes all documents using OpenAPI 3.0 as the internal format.
52
+ * This function handles version detection and conversion from:
53
+ * - OpenAPI 3.0.x (returned as-is)
54
+ * - OpenAPI 3.1.x (downgraded to 3.0 with allOf transformations)
55
+ * - Swagger 2.0 (upgraded to OpenAPI 3.0)
56
+ *
57
+ * @param schema - The OpenAPI document to convert
58
+ * @returns Promise resolving to an OpenAPI 3.0 document
59
+ *
60
+ * @example Converting OpenAPI 3.1 to 3.0
61
+ * ```typescript
62
+ * const openapi31Doc = {
63
+ * openapi: "3.1.0",
64
+ * info: { title: "My API", version: "1.0.0" },
65
+ * paths: {}
66
+ * };
67
+ * const v3Doc = await toV3Document(openapi31Doc);
68
+ * console.log(v3Doc.openapi); // "3.0.3" (converted)
69
+ * ```
70
+ *
71
+ * @example Converting Swagger 2.0 to OpenAPI 3.0
72
+ * ```typescript
73
+ * const swagger2Doc = {
74
+ * swagger: "2.0",
75
+ * info: { title: "My API", version: "1.0.0" },
76
+ * paths: {}
77
+ * };
78
+ * const v3Doc = await toV3Document(swagger2Doc);
79
+ * console.log(v3Doc.openapi); // "3.0.0" (converted)
80
+ * ```
81
+ *
82
+ * @example OpenAPI 3.0 passthrough
83
+ * ```typescript
84
+ * const openapi30Doc = {
85
+ * openapi: "3.0.2",
86
+ * info: { title: "My API", version: "1.0.0" },
87
+ * paths: {}
88
+ * };
89
+ * const v3Doc = await toV3Document(openapi30Doc);
90
+ * console.log(v3Doc === openapi30Doc); // true (same object)
91
+ * ```
92
+ *
93
+ * @throws {Error} If the document version is not recognized or supported
94
+ */
5
95
  export declare const toV3Document: (schema: AnyOasDocument) => Promise<OpenAPIV3.Document>;
6
96
  export {};
7
97
  //# sourceMappingURL=toV3JsonDocument.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toV3JsonDocument.d.ts","sourceRoot":"","sources":["../../src/run/toV3JsonDocument.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAUtE,KAAK,cAAc,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;AAEpF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,cAM/C,CAAA;AAED,eAAO,MAAM,YAAY,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CA0BrF,CAAA"}
1
+ {"version":3,"file":"toV3JsonDocument.d.ts","sourceRoot":"","sources":["../../src/run/toV3JsonDocument.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAUtE;;;;;GAKG;AACH,KAAK,cAAc,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,cAM/C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CA0BrF,CAAA"}
@@ -9,6 +9,43 @@ const parse_js_1 = require("../deps/jsr.io/@std/yaml/1.0.9/parse.js");
9
9
  const openapi_down_convert_1 = require("@apiture/openapi-down-convert");
10
10
  const ts_pattern_1 = require("ts-pattern");
11
11
  const swagger2openapi_1 = __importDefault(require("swagger2openapi"));
12
+ /**
13
+ * Parses a string into an OpenAPI document object.
14
+ *
15
+ * Automatically detects whether the input string is JSON or YAML format based on
16
+ * the content, then parses it into an OpenAPI document object. Supports all
17
+ * OpenAPI versions (2.0, 3.0.x, 3.1.x).
18
+ *
19
+ * @param schema - The OpenAPI document as a JSON or YAML string
20
+ * @returns Parsed OpenAPI document object
21
+ *
22
+ * @example Parsing JSON OpenAPI document
23
+ * ```typescript
24
+ * const jsonSchema = `{
25
+ * "openapi": "3.0.0",
26
+ * "info": { "title": "My API", "version": "1.0.0" },
27
+ * "paths": {}
28
+ * }`;
29
+ * const document = stringToSchema(jsonSchema);
30
+ * console.log(document.info.title); // "My API"
31
+ * ```
32
+ *
33
+ * @example Parsing YAML OpenAPI document
34
+ * ```typescript
35
+ * const yamlSchema = `
36
+ * openapi: 3.0.0
37
+ * info:
38
+ * title: My API
39
+ * version: 1.0.0
40
+ * paths: {}
41
+ * `;
42
+ * const document = stringToSchema(yamlSchema);
43
+ * console.log(document.info.title); // "My API"
44
+ * ```
45
+ *
46
+ * @throws {SyntaxError} If the JSON is malformed
47
+ * @throws {Error} If the YAML is malformed
48
+ */
12
49
  const stringToSchema = (schema) => {
13
50
  if (schema.trimStart().startsWith('{')) {
14
51
  return JSON.parse(schema);
@@ -18,6 +55,53 @@ const stringToSchema = (schema) => {
18
55
  }
19
56
  };
20
57
  exports.stringToSchema = stringToSchema;
58
+ /**
59
+ * Converts any OpenAPI document version to OpenAPI 3.0 format.
60
+ *
61
+ * SKMTC processes all documents using OpenAPI 3.0 as the internal format.
62
+ * This function handles version detection and conversion from:
63
+ * - OpenAPI 3.0.x (returned as-is)
64
+ * - OpenAPI 3.1.x (downgraded to 3.0 with allOf transformations)
65
+ * - Swagger 2.0 (upgraded to OpenAPI 3.0)
66
+ *
67
+ * @param schema - The OpenAPI document to convert
68
+ * @returns Promise resolving to an OpenAPI 3.0 document
69
+ *
70
+ * @example Converting OpenAPI 3.1 to 3.0
71
+ * ```typescript
72
+ * const openapi31Doc = {
73
+ * openapi: "3.1.0",
74
+ * info: { title: "My API", version: "1.0.0" },
75
+ * paths: {}
76
+ * };
77
+ * const v3Doc = await toV3Document(openapi31Doc);
78
+ * console.log(v3Doc.openapi); // "3.0.3" (converted)
79
+ * ```
80
+ *
81
+ * @example Converting Swagger 2.0 to OpenAPI 3.0
82
+ * ```typescript
83
+ * const swagger2Doc = {
84
+ * swagger: "2.0",
85
+ * info: { title: "My API", version: "1.0.0" },
86
+ * paths: {}
87
+ * };
88
+ * const v3Doc = await toV3Document(swagger2Doc);
89
+ * console.log(v3Doc.openapi); // "3.0.0" (converted)
90
+ * ```
91
+ *
92
+ * @example OpenAPI 3.0 passthrough
93
+ * ```typescript
94
+ * const openapi30Doc = {
95
+ * openapi: "3.0.2",
96
+ * info: { title: "My API", version: "1.0.0" },
97
+ * paths: {}
98
+ * };
99
+ * const v3Doc = await toV3Document(openapi30Doc);
100
+ * console.log(v3Doc === openapi30Doc); // true (same object)
101
+ * ```
102
+ *
103
+ * @throws {Error} If the document version is not recognized or supported
104
+ */
21
105
  const toV3Document = async (schema) => {
22
106
  return await (0, ts_pattern_1.match)(schema)
23
107
  .with({ openapi: ts_pattern_1.P.string.startsWith('3.0') }, doc => doc)