@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
@@ -1,4 +1,142 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema format values with type safety.
4
+ *
5
+ * This function extracts and validates format specifiers from OpenAPI schema objects,
6
+ * ensuring they conform to expected format types for the given schema. Invalid format
7
+ * values are removed and logged as warnings through the parse context.
8
+ *
9
+ * The format property provides additional semantic information about the expected
10
+ * structure of string values (like 'email', 'date-time', 'uuid', etc.) and numeric
11
+ * precision (like 'float', 'double' for numbers, 'int32', 'int64' for integers).
12
+ *
13
+ * @template T - The expected type of the format value (usually string)
14
+ * @template Value - The OpenAPI schema object type
15
+ *
16
+ * @param args - Parsing configuration
17
+ * @returns Parsed format data with the validated format and cleaned schema
18
+ *
19
+ * @example String format parsing
20
+ * ```typescript
21
+ * import { parseFormat } from '@skmtc/core/oas/_helpers';
22
+ * import * as v from 'valibot';
23
+ *
24
+ * const result = parseFormat({
25
+ * value: {
26
+ * type: 'string',
27
+ * format: 'email',
28
+ * maxLength: 100
29
+ * },
30
+ * valibotSchema: v.string(),
31
+ * context: parseContext
32
+ * });
33
+ *
34
+ * console.log(result.format); // 'email'
35
+ * console.log(result.value); // { type: 'string', maxLength: 100 }
36
+ * ```
37
+ *
38
+ * @example Date-time format
39
+ * ```typescript
40
+ * const result = parseFormat({
41
+ * value: {
42
+ * type: 'string',
43
+ * format: 'date-time',
44
+ * description: 'ISO 8601 timestamp'
45
+ * },
46
+ * valibotSchema: v.string(),
47
+ * context: parseContext
48
+ * });
49
+ *
50
+ * console.log(result.format); // 'date-time'
51
+ * // Can be used to generate Date objects in TypeScript
52
+ * ```
53
+ *
54
+ * @example Number precision formats
55
+ * ```typescript
56
+ * const result = parseFormat({
57
+ * value: {
58
+ * type: 'number',
59
+ * format: 'float',
60
+ * minimum: 0
61
+ * },
62
+ * valibotSchema: v.string(), // Format is always a string
63
+ * context: parseContext
64
+ * });
65
+ *
66
+ * console.log(result.format); // 'float'
67
+ * // Indicates single-precision floating-point
68
+ * ```
69
+ *
70
+ * @example Integer format specifiers
71
+ * ```typescript
72
+ * const result = parseFormat({
73
+ * value: {
74
+ * type: 'integer',
75
+ * format: 'int64',
76
+ * description: 'Large integer ID'
77
+ * },
78
+ * valibotSchema: v.string(),
79
+ * context: parseContext
80
+ * });
81
+ *
82
+ * console.log(result.format); // 'int64'
83
+ * // Indicates 64-bit signed integer
84
+ * ```
85
+ *
86
+ * @example Invalid format handling
87
+ * ```typescript
88
+ * const result = parseFormat({
89
+ * value: {
90
+ * type: 'string',
91
+ * format: 123, // Invalid - should be string
92
+ * pattern: '^[a-z]+$'
93
+ * } as any,
94
+ * valibotSchema: v.string(),
95
+ * context: parseContext
96
+ * });
97
+ *
98
+ * console.log(result.format); // undefined (invalid format removed)
99
+ * console.log(result.value); // { type: 'string', pattern: '^[a-z]+$' }
100
+ * // Context will log a warning about the invalid format
101
+ * ```
102
+ *
103
+ * @example Missing format (undefined)
104
+ * ```typescript
105
+ * const result = parseFormat({
106
+ * value: {
107
+ * type: 'string',
108
+ * minLength: 1,
109
+ * maxLength: 50
110
+ * },
111
+ * valibotSchema: v.string(),
112
+ * context: parseContext
113
+ * });
114
+ *
115
+ * console.log(result.format); // undefined (no format specified)
116
+ * console.log(result.value); // { type: 'string', minLength: 1, maxLength: 50 }
117
+ * ```
118
+ *
119
+ * @example Common string formats
120
+ * ```typescript
121
+ * // Standard OpenAPI string formats:
122
+ * // - 'date': full-date as defined by RFC3339
123
+ * // - 'date-time': date-time as defined by RFC3339
124
+ * // - 'time': time as defined by RFC3339
125
+ * // - 'email': email address as defined by RFC5322
126
+ * // - 'uri': URI as defined by RFC3986
127
+ * // - 'uuid': UUID as defined by RFC4122
128
+ * // - 'binary': binary data (base64 encoded)
129
+ * // - 'byte': base64 encoded characters
130
+ * // - 'password': hint for UI to obscure input
131
+ *
132
+ * const emailFormat = parseFormat({
133
+ * value: { type: 'string', format: 'email' },
134
+ * valibotSchema: v.string(),
135
+ * context
136
+ * });
137
+ * // Can generate validation: v.pipe(v.string(), v.email())
138
+ * ```
139
+ */
2
140
  export const parseFormat = ({ value, valibotSchema, context }) => {
3
141
  const { format, ...rest } = value;
4
142
  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"}
@@ -1,4 +1,117 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates the nullable property from OpenAPI schema objects.
4
+ *
5
+ * This function extracts and validates the `nullable` property from OpenAPI
6
+ * schema objects, ensuring it's a valid boolean value. Invalid nullable values
7
+ * are removed and logged as warnings through the parse context.
8
+ *
9
+ * The nullable property determines whether a schema value can be null in addition
10
+ * to its primary type, which affects type generation and validation logic.
11
+ *
12
+ * @template Value - The OpenAPI schema object type
13
+ *
14
+ * @param args - Parsing configuration
15
+ * @returns Parsed nullable data with the validated flag and cleaned schema
16
+ *
17
+ * @example Valid nullable property
18
+ * ```typescript
19
+ * import { parseNullable } from '@skmtc/core/oas/_helpers';
20
+ *
21
+ * const result = parseNullable({
22
+ * value: {
23
+ * type: 'string',
24
+ * nullable: true,
25
+ * description: 'An optional string that can be null'
26
+ * },
27
+ * context: parseContext
28
+ * });
29
+ *
30
+ * console.log(result.nullable); // true
31
+ * console.log(result.value); // { type: 'string', description: 'An optional string that can be null' }
32
+ * ```
33
+ *
34
+ * @example Explicitly non-nullable
35
+ * ```typescript
36
+ * const result = parseNullable({
37
+ * value: {
38
+ * type: 'number',
39
+ * nullable: false,
40
+ * minimum: 0
41
+ * },
42
+ * context: parseContext
43
+ * });
44
+ *
45
+ * console.log(result.nullable); // false
46
+ * console.log(result.value); // { type: 'number', minimum: 0 }
47
+ * ```
48
+ *
49
+ * @example Missing nullable property (undefined)
50
+ * ```typescript
51
+ * const result = parseNullable({
52
+ * value: {
53
+ * type: 'string',
54
+ * format: 'email'
55
+ * },
56
+ * context: parseContext
57
+ * });
58
+ *
59
+ * console.log(result.nullable); // undefined (property not present)
60
+ * console.log(result.value); // { type: 'string', format: 'email' }
61
+ * ```
62
+ *
63
+ * @example Invalid nullable value
64
+ * ```typescript
65
+ * const result = parseNullable({
66
+ * value: {
67
+ * type: 'boolean',
68
+ * nullable: 'yes', // Invalid - should be boolean
69
+ * description: 'A flag'
70
+ * } as any,
71
+ * context: parseContext
72
+ * });
73
+ *
74
+ * console.log(result.nullable); // undefined (invalid value removed)
75
+ * console.log(result.value); // { type: 'boolean', description: 'A flag' }
76
+ * // Context will log a warning about the invalid nullable value
77
+ * ```
78
+ *
79
+ * @example Usage in type generation
80
+ * ```typescript
81
+ * function generateTypeScript(schema: OpenAPIV3.SchemaObject) {
82
+ * const { nullable, value } = parseNullable({ value: schema, context });
83
+ *
84
+ * const baseType = generateBaseType(value);
85
+ * const nullableType = nullable ? ` | null` : '';
86
+ *
87
+ * return `${baseType}${nullableType}`;
88
+ * }
89
+ *
90
+ * // Examples:
91
+ * // nullable: true -> 'string | null'
92
+ * // nullable: false -> 'string'
93
+ * // nullable: undefined -> 'string' (default behavior)
94
+ * ```
95
+ *
96
+ * @example Complex schema with nullable
97
+ * ```typescript
98
+ * const result = parseNullable({
99
+ * value: {
100
+ * type: 'object',
101
+ * properties: {
102
+ * name: { type: 'string' },
103
+ * age: { type: 'number' }
104
+ * },
105
+ * required: ['name'],
106
+ * nullable: true // The entire object can be null
107
+ * },
108
+ * context: parseContext
109
+ * });
110
+ *
111
+ * console.log(result.nullable); // true
112
+ * // Generated type might be: { name: string; age?: number } | null
113
+ * ```
114
+ */
2
115
  export const parseNullable = ({ value, context }) => {
3
116
  const { nullable, ...rest } = value;
4
117
  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"}
@@ -3,6 +3,43 @@ import { parse as parseYaml } from '../deps/jsr.io/@std/yaml/1.0.9/parse.js';
3
3
  import { Converter as ThreeOneToThreeZeroConverter } from '@apiture/openapi-down-convert';
4
4
  import { match, P } from 'ts-pattern';
5
5
  import converter from 'swagger2openapi';
6
+ /**
7
+ * Parses a string into an OpenAPI document object.
8
+ *
9
+ * Automatically detects whether the input string is JSON or YAML format based on
10
+ * the content, then parses it into an OpenAPI document object. Supports all
11
+ * OpenAPI versions (2.0, 3.0.x, 3.1.x).
12
+ *
13
+ * @param schema - The OpenAPI document as a JSON or YAML string
14
+ * @returns Parsed OpenAPI document object
15
+ *
16
+ * @example Parsing JSON OpenAPI document
17
+ * ```typescript
18
+ * const jsonSchema = `{
19
+ * "openapi": "3.0.0",
20
+ * "info": { "title": "My API", "version": "1.0.0" },
21
+ * "paths": {}
22
+ * }`;
23
+ * const document = stringToSchema(jsonSchema);
24
+ * console.log(document.info.title); // "My API"
25
+ * ```
26
+ *
27
+ * @example Parsing YAML OpenAPI document
28
+ * ```typescript
29
+ * const yamlSchema = `
30
+ * openapi: 3.0.0
31
+ * info:
32
+ * title: My API
33
+ * version: 1.0.0
34
+ * paths: {}
35
+ * `;
36
+ * const document = stringToSchema(yamlSchema);
37
+ * console.log(document.info.title); // "My API"
38
+ * ```
39
+ *
40
+ * @throws {SyntaxError} If the JSON is malformed
41
+ * @throws {Error} If the YAML is malformed
42
+ */
6
43
  export const stringToSchema = (schema) => {
7
44
  if (schema.trimStart().startsWith('{')) {
8
45
  return JSON.parse(schema);
@@ -11,6 +48,53 @@ export const stringToSchema = (schema) => {
11
48
  return parseYaml(schema);
12
49
  }
13
50
  };
51
+ /**
52
+ * Converts any OpenAPI document version to OpenAPI 3.0 format.
53
+ *
54
+ * SKMTC processes all documents using OpenAPI 3.0 as the internal format.
55
+ * This function handles version detection and conversion from:
56
+ * - OpenAPI 3.0.x (returned as-is)
57
+ * - OpenAPI 3.1.x (downgraded to 3.0 with allOf transformations)
58
+ * - Swagger 2.0 (upgraded to OpenAPI 3.0)
59
+ *
60
+ * @param schema - The OpenAPI document to convert
61
+ * @returns Promise resolving to an OpenAPI 3.0 document
62
+ *
63
+ * @example Converting OpenAPI 3.1 to 3.0
64
+ * ```typescript
65
+ * const openapi31Doc = {
66
+ * openapi: "3.1.0",
67
+ * info: { title: "My API", version: "1.0.0" },
68
+ * paths: {}
69
+ * };
70
+ * const v3Doc = await toV3Document(openapi31Doc);
71
+ * console.log(v3Doc.openapi); // "3.0.3" (converted)
72
+ * ```
73
+ *
74
+ * @example Converting Swagger 2.0 to OpenAPI 3.0
75
+ * ```typescript
76
+ * const swagger2Doc = {
77
+ * swagger: "2.0",
78
+ * info: { title: "My API", version: "1.0.0" },
79
+ * paths: {}
80
+ * };
81
+ * const v3Doc = await toV3Document(swagger2Doc);
82
+ * console.log(v3Doc.openapi); // "3.0.0" (converted)
83
+ * ```
84
+ *
85
+ * @example OpenAPI 3.0 passthrough
86
+ * ```typescript
87
+ * const openapi30Doc = {
88
+ * openapi: "3.0.2",
89
+ * info: { title: "My API", version: "1.0.0" },
90
+ * paths: {}
91
+ * };
92
+ * const v3Doc = await toV3Document(openapi30Doc);
93
+ * console.log(v3Doc === openapi30Doc); // true (same object)
94
+ * ```
95
+ *
96
+ * @throws {Error} If the document version is not recognized or supported
97
+ */
14
98
  export const toV3Document = async (schema) => {
15
99
  return await match(schema)
16
100
  .with({ openapi: P.string.startsWith('3.0') }, doc => doc)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.795",
3
+ "version": "0.0.797",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/skmtc/skmtc.git"
@@ -1,3 +1,35 @@
1
+ /**
2
+ * Validates a project name against SKMTC naming conventions.
3
+ *
4
+ * Ensures project names follow standard naming patterns suitable for package
5
+ * managers and file systems. Names must be lowercase, contain only letters,
6
+ * numbers, and hyphens, with specific length and format requirements.
7
+ *
8
+ * @param name - The project name to validate
9
+ * @returns An error message string if validation fails, undefined if valid
10
+ *
11
+ * @example Valid project names
12
+ * ```typescript
13
+ * checkProjectName('my-api-client'); // undefined (valid)
14
+ * checkProjectName('user-service'); // undefined (valid)
15
+ * checkProjectName('api2'); // undefined (valid)
16
+ * ```
17
+ *
18
+ * @example Invalid project names
19
+ * ```typescript
20
+ * checkProjectName('A'); // 'Name must be at least 2 characters long'
21
+ * checkProjectName('My-API-Client'); // 'Name must only contain lowercase letters, numbers and hyphens'
22
+ * checkProjectName('-api-client'); // 'Name cannot start with a hyphen'
23
+ * checkProjectName('api-client-'); // 'Name cannot end with a hyphen'
24
+ * ```
25
+ *
26
+ * @example Validation rules
27
+ * - Minimum length: 2 characters
28
+ * - Maximum length: 20 characters
29
+ * - Allowed characters: a-z, 0-9, hyphens (-)
30
+ * - Cannot start or end with hyphen
31
+ * - Must be lowercase only
32
+ */
1
33
  import "../_dnt.polyfills.js";
2
34
  export declare const checkProjectName: (name: string) => string | undefined;
3
35
  //# sourceMappingURL=validate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/app/validate.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAoBxD,CAAA"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/app/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAoBxD,CAAA"}