@skmtc/core 0.0.796 → 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 (55) 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/dsl/constants.d.ts +28 -0
  8. package/esm/dsl/constants.d.ts.map +1 -1
  9. package/esm/dsl/constants.js +28 -0
  10. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  11. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  12. package/esm/oas/_helpers/parseDefault.js +128 -0
  13. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  14. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  15. package/esm/oas/_helpers/parseEnum.js +104 -0
  16. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  17. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseExample.js +87 -0
  19. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  20. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseFormat.js +138 -0
  22. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  23. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseNullable.js +113 -0
  25. package/esm/run/toV3JsonDocument.d.ts +90 -0
  26. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  27. package/esm/run/toV3JsonDocument.js +84 -0
  28. package/package.json +1 -1
  29. package/script/app/validate.d.ts +32 -0
  30. package/script/app/validate.d.ts.map +1 -1
  31. package/script/app/validate.js +32 -0
  32. package/script/context/CoreContext.d.ts +137 -1
  33. package/script/context/CoreContext.d.ts.map +1 -1
  34. package/script/context/CoreContext.js +87 -0
  35. package/script/dsl/constants.d.ts +28 -0
  36. package/script/dsl/constants.d.ts.map +1 -1
  37. package/script/dsl/constants.js +28 -0
  38. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  39. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  40. package/script/oas/_helpers/parseDefault.js +128 -0
  41. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  42. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  43. package/script/oas/_helpers/parseEnum.js +104 -0
  44. package/script/oas/_helpers/parseExample.d.ts +107 -0
  45. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  46. package/script/oas/_helpers/parseExample.js +87 -0
  47. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  48. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  49. package/script/oas/_helpers/parseFormat.js +138 -0
  50. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  51. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  52. package/script/oas/_helpers/parseNullable.js +113 -0
  53. package/script/run/toV3JsonDocument.d.ts +90 -0
  54. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  55. package/script/run/toV3JsonDocument.js +84 -0
@@ -1,15 +1,169 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContext } from '../../context/ParseContext.js';
3
3
  import * as v from 'valibot';
4
+ /**
5
+ * Arguments for parsing OpenAPI schema format values.
6
+ *
7
+ * @template T - The expected type of the format value
8
+ */
4
9
  type ParseFormatArgs<T> = {
10
+ /** The OpenAPI schema object with processed properties removed */
5
11
  value: Omit<OpenAPIV3.SchemaObject, 'nullable' | 'example' | 'enums'>;
12
+ /** Valibot schema for validating the format value */
6
13
  valibotSchema: v.GenericSchema<T>;
14
+ /** Parse context for error handling */
7
15
  context: ParseContext;
8
16
  };
17
+ /**
18
+ * Return type for parsed format data.
19
+ *
20
+ * @template T - The expected type of the format value
21
+ * @template Value - The OpenAPI schema object type
22
+ */
9
23
  type ParseFormatReturn<T, Value extends OpenAPIV3.SchemaObject> = {
24
+ /** The parsed and validated format string */
10
25
  format: T | undefined;
26
+ /** The schema object without the format property */
11
27
  value: Omit<Value, 'format'>;
12
28
  };
29
+ /**
30
+ * Parses and validates OpenAPI schema format values with type safety.
31
+ *
32
+ * This function extracts and validates format specifiers from OpenAPI schema objects,
33
+ * ensuring they conform to expected format types for the given schema. Invalid format
34
+ * values are removed and logged as warnings through the parse context.
35
+ *
36
+ * The format property provides additional semantic information about the expected
37
+ * structure of string values (like 'email', 'date-time', 'uuid', etc.) and numeric
38
+ * precision (like 'float', 'double' for numbers, 'int32', 'int64' for integers).
39
+ *
40
+ * @template T - The expected type of the format value (usually string)
41
+ * @template Value - The OpenAPI schema object type
42
+ *
43
+ * @param args - Parsing configuration
44
+ * @returns Parsed format data with the validated format and cleaned schema
45
+ *
46
+ * @example String format parsing
47
+ * ```typescript
48
+ * import { parseFormat } from '@skmtc/core/oas/_helpers';
49
+ * import * as v from 'valibot';
50
+ *
51
+ * const result = parseFormat({
52
+ * value: {
53
+ * type: 'string',
54
+ * format: 'email',
55
+ * maxLength: 100
56
+ * },
57
+ * valibotSchema: v.string(),
58
+ * context: parseContext
59
+ * });
60
+ *
61
+ * console.log(result.format); // 'email'
62
+ * console.log(result.value); // { type: 'string', maxLength: 100 }
63
+ * ```
64
+ *
65
+ * @example Date-time format
66
+ * ```typescript
67
+ * const result = parseFormat({
68
+ * value: {
69
+ * type: 'string',
70
+ * format: 'date-time',
71
+ * description: 'ISO 8601 timestamp'
72
+ * },
73
+ * valibotSchema: v.string(),
74
+ * context: parseContext
75
+ * });
76
+ *
77
+ * console.log(result.format); // 'date-time'
78
+ * // Can be used to generate Date objects in TypeScript
79
+ * ```
80
+ *
81
+ * @example Number precision formats
82
+ * ```typescript
83
+ * const result = parseFormat({
84
+ * value: {
85
+ * type: 'number',
86
+ * format: 'float',
87
+ * minimum: 0
88
+ * },
89
+ * valibotSchema: v.string(), // Format is always a string
90
+ * context: parseContext
91
+ * });
92
+ *
93
+ * console.log(result.format); // 'float'
94
+ * // Indicates single-precision floating-point
95
+ * ```
96
+ *
97
+ * @example Integer format specifiers
98
+ * ```typescript
99
+ * const result = parseFormat({
100
+ * value: {
101
+ * type: 'integer',
102
+ * format: 'int64',
103
+ * description: 'Large integer ID'
104
+ * },
105
+ * valibotSchema: v.string(),
106
+ * context: parseContext
107
+ * });
108
+ *
109
+ * console.log(result.format); // 'int64'
110
+ * // Indicates 64-bit signed integer
111
+ * ```
112
+ *
113
+ * @example Invalid format handling
114
+ * ```typescript
115
+ * const result = parseFormat({
116
+ * value: {
117
+ * type: 'string',
118
+ * format: 123, // Invalid - should be string
119
+ * pattern: '^[a-z]+$'
120
+ * } as any,
121
+ * valibotSchema: v.string(),
122
+ * context: parseContext
123
+ * });
124
+ *
125
+ * console.log(result.format); // undefined (invalid format removed)
126
+ * console.log(result.value); // { type: 'string', pattern: '^[a-z]+$' }
127
+ * // Context will log a warning about the invalid format
128
+ * ```
129
+ *
130
+ * @example Missing format (undefined)
131
+ * ```typescript
132
+ * const result = parseFormat({
133
+ * value: {
134
+ * type: 'string',
135
+ * minLength: 1,
136
+ * maxLength: 50
137
+ * },
138
+ * valibotSchema: v.string(),
139
+ * context: parseContext
140
+ * });
141
+ *
142
+ * console.log(result.format); // undefined (no format specified)
143
+ * console.log(result.value); // { type: 'string', minLength: 1, maxLength: 50 }
144
+ * ```
145
+ *
146
+ * @example Common string formats
147
+ * ```typescript
148
+ * // Standard OpenAPI string formats:
149
+ * // - 'date': full-date as defined by RFC3339
150
+ * // - 'date-time': date-time as defined by RFC3339
151
+ * // - 'time': time as defined by RFC3339
152
+ * // - 'email': email address as defined by RFC5322
153
+ * // - 'uri': URI as defined by RFC3986
154
+ * // - 'uuid': UUID as defined by RFC4122
155
+ * // - 'binary': binary data (base64 encoded)
156
+ * // - 'byte': base64 encoded characters
157
+ * // - 'password': hint for UI to obscure input
158
+ *
159
+ * const emailFormat = parseFormat({
160
+ * value: { type: 'string', format: 'email' },
161
+ * valibotSchema: v.string(),
162
+ * context
163
+ * });
164
+ * // Can generate validation: v.pipe(v.string(), v.email())
165
+ * ```
166
+ */
13
167
  export declare const parseFormat: <T, Value extends OpenAPIV3.SchemaObject>({ value, valibotSchema, context }: ParseFormatArgs<T>) => ParseFormatReturn<T, Value>;
14
168
  export {};
15
169
  //# sourceMappingURL=parseFormat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseFormat.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAA;IACrE,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,KAAK,iBAAiB,CAAC,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IAChE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAA;IACrB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,mCAIlE,eAAe,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAgBjD,CAAA"}
1
+ {"version":3,"file":"parseFormat.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;GAIG;AACH,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,kEAAkE;IAClE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAA;IACrE,qDAAqD;IACrD,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;GAKG;AACH,KAAK,iBAAiB,CAAC,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IAChE,6CAA6C;IAC7C,MAAM,EAAE,CAAC,GAAG,SAAS,CAAA;IACrB,oDAAoD;IACpD,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,mCAIlE,eAAe,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAgBjD,CAAA"}
@@ -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"}