@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,4 +1,132 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema default values with type safety.
4
+ *
5
+ * This function extracts and validates default values from OpenAPI schema objects,
6
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
7
+ * Invalid default values are removed and logged as warnings through the parse context.
8
+ *
9
+ * The function provides full type safety, with the return type reflecting whether
10
+ * null values are allowed based on the nullable parameter. This ensures that
11
+ * generated code maintains proper type constraints for default values.
12
+ *
13
+ * @template T - The expected type of the default value
14
+ * @template Nullable - Whether the schema allows null as a default
15
+ * @template Value - The OpenAPI schema object type
16
+ *
17
+ * @param args - Parsing configuration
18
+ * @returns Parsed default data with the validated default value and cleaned schema
19
+ *
20
+ * @example Basic string default parsing
21
+ * ```typescript
22
+ * import { parseDefault } from '@skmtc/core/oas/_helpers';
23
+ * import * as v from 'valibot';
24
+ *
25
+ * const result = parseDefault({
26
+ * value: {
27
+ * type: 'string',
28
+ * default: 'hello world',
29
+ * minLength: 5
30
+ * },
31
+ * nullable: false,
32
+ * valibotSchema: v.string(),
33
+ * context: parseContext
34
+ * });
35
+ *
36
+ * console.log(result.default); // 'hello world'
37
+ * console.log(result.value); // { type: 'string', minLength: 5 }
38
+ * ```
39
+ *
40
+ * @example Nullable default value
41
+ * ```typescript
42
+ * const result = parseDefault({
43
+ * value: {
44
+ * type: 'string',
45
+ * default: null,
46
+ * format: 'email'
47
+ * },
48
+ * nullable: true,
49
+ * valibotSchema: v.string(),
50
+ * context: parseContext
51
+ * });
52
+ *
53
+ * console.log(result.default); // null (valid for nullable schema)
54
+ * // Type: string | null | undefined
55
+ * ```
56
+ *
57
+ * @example Number default with constraints
58
+ * ```typescript
59
+ * const result = parseDefault({
60
+ * value: {
61
+ * type: 'number',
62
+ * default: 42,
63
+ * minimum: 0,
64
+ * maximum: 100
65
+ * },
66
+ * nullable: false,
67
+ * valibotSchema: v.number(),
68
+ * context: parseContext
69
+ * });
70
+ *
71
+ * console.log(result.default); // 42
72
+ * console.log(result.value); // { type: 'number', minimum: 0, maximum: 100 }
73
+ * ```
74
+ *
75
+ * @example Invalid default handling
76
+ * ```typescript
77
+ * const result = parseDefault({
78
+ * value: {
79
+ * type: 'boolean',
80
+ * default: 'not a boolean', // Invalid default
81
+ * description: 'A boolean flag'
82
+ * },
83
+ * nullable: false,
84
+ * valibotSchema: v.boolean(),
85
+ * context: parseContext
86
+ * });
87
+ *
88
+ * console.log(result.default); // undefined (invalid default removed)
89
+ * // Context will log a warning about the invalid default
90
+ * ```
91
+ *
92
+ * @example Array default value
93
+ * ```typescript
94
+ * const result = parseDefault({
95
+ * value: {
96
+ * type: 'array',
97
+ * items: { type: 'string' },
98
+ * default: ['item1', 'item2']
99
+ * },
100
+ * nullable: false,
101
+ * valibotSchema: v.array(v.string()),
102
+ * context: parseContext
103
+ * });
104
+ *
105
+ * console.log(result.default); // ['item1', 'item2']
106
+ * ```
107
+ *
108
+ * @example Object default value
109
+ * ```typescript
110
+ * const result = parseDefault({
111
+ * value: {
112
+ * type: 'object',
113
+ * properties: {
114
+ * name: { type: 'string' },
115
+ * age: { type: 'number' }
116
+ * },
117
+ * default: { name: 'John', age: 30 }
118
+ * },
119
+ * nullable: false,
120
+ * valibotSchema: v.object({
121
+ * name: v.string(),
122
+ * age: v.number()
123
+ * }),
124
+ * context: parseContext
125
+ * });
126
+ *
127
+ * console.log(result.default); // { name: 'John', age: 30 }
128
+ * ```
129
+ */
2
130
  export const parseDefault = ({ value, nullable, valibotSchema, context }) => {
3
131
  const { default: defaultValue, ...rest } = value;
4
132
  const parsedDefault = context.provisionalParse({
@@ -1,16 +1,140 @@
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 enum values.
6
+ *
7
+ * @template T - The expected type of enum values
8
+ * @template Nullable - Whether the schema allows null values
9
+ * @template Value - The OpenAPI schema object type
10
+ */
4
11
  type ParseEnumArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
12
+ /** The OpenAPI schema object without nullable property */
5
13
  value: Omit<Value, 'nullable'>;
14
+ /** Whether the schema allows null values */
6
15
  nullable: Nullable;
16
+ /** Valibot schema for validating enum values */
7
17
  valibotSchema: v.GenericSchema<T>;
18
+ /** Parse context for error handling */
8
19
  context: ParseContext;
9
20
  };
21
+ /**
22
+ * Return type for parsed enum data.
23
+ *
24
+ * @template T - The expected type of enum values
25
+ * @template Nullable - Whether the schema allows null values
26
+ * @template Value - The OpenAPI schema object type
27
+ */
10
28
  type ParseEnumReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
29
+ /** The parsed and validated enum array */
11
30
  enum: Nullable extends true ? (T | null)[] | undefined : T[] | undefined;
31
+ /** The schema object without enum and nullable properties */
12
32
  value: Omit<Value, 'nullable' | 'enum'>;
13
33
  };
34
+ /**
35
+ * Parses and validates OpenAPI schema enum values with type safety.
36
+ *
37
+ * This function extracts and validates enum arrays from OpenAPI schema objects,
38
+ * ensuring all enum values conform to the expected type and handling nullable
39
+ * schemas correctly. Invalid enum values are removed and logged as warnings
40
+ * through the parse context.
41
+ *
42
+ * The function provides full type safety, with the return type reflecting whether
43
+ * null values are allowed in the enum array based on the nullable parameter.
44
+ *
45
+ * @template T - The expected type of enum values
46
+ * @template Nullable - Whether the schema allows null values in enums
47
+ * @template Value - The OpenAPI schema object type
48
+ *
49
+ * @param args - Parsing configuration
50
+ * @returns Parsed enum data with the validated enum array and cleaned schema
51
+ *
52
+ * @example Basic string enum parsing
53
+ * ```typescript
54
+ * import { parseEnum } from '@skmtc/core/oas/_helpers';
55
+ * import * as v from 'valibot';
56
+ *
57
+ * const result = parseEnum({
58
+ * value: {
59
+ * type: 'string',
60
+ * enum: ['active', 'inactive', 'pending'],
61
+ * description: 'User status'
62
+ * },
63
+ * nullable: false,
64
+ * valibotSchema: v.string(),
65
+ * context: parseContext
66
+ * });
67
+ *
68
+ * console.log(result.enum); // ['active', 'inactive', 'pending']
69
+ * console.log(result.value); // { type: 'string', description: 'User status' }
70
+ * ```
71
+ *
72
+ * @example Nullable enum parsing
73
+ * ```typescript
74
+ * const result = parseEnum({
75
+ * value: {
76
+ * type: 'string',
77
+ * enum: ['red', 'green', 'blue', null],
78
+ * description: 'Optional color selection'
79
+ * },
80
+ * nullable: true,
81
+ * valibotSchema: v.string(),
82
+ * context: parseContext
83
+ * });
84
+ *
85
+ * console.log(result.enum); // ['red', 'green', 'blue', null]
86
+ * // Type: (string | null)[] | undefined
87
+ * ```
88
+ *
89
+ * @example Number enum parsing
90
+ * ```typescript
91
+ * const result = parseEnum({
92
+ * value: {
93
+ * type: 'number',
94
+ * enum: [1, 2, 3, 5, 8, 13],
95
+ * description: 'Fibonacci subset'
96
+ * },
97
+ * nullable: false,
98
+ * valibotSchema: v.number(),
99
+ * context: parseContext
100
+ * });
101
+ *
102
+ * console.log(result.enum); // [1, 2, 3, 5, 8, 13]
103
+ * ```
104
+ *
105
+ * @example Invalid enum handling
106
+ * ```typescript
107
+ * const result = parseEnum({
108
+ * value: {
109
+ * type: 'number',
110
+ * enum: [1, 'invalid', 3], // Contains invalid value
111
+ * description: 'Mixed enum (invalid)'
112
+ * },
113
+ * nullable: false,
114
+ * valibotSchema: v.number(),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.enum); // undefined (entire enum removed due to invalid value)
119
+ * // Context will log a warning about the invalid enum
120
+ * ```
121
+ *
122
+ * @example Boolean enum (essentially optional boolean)
123
+ * ```typescript
124
+ * const result = parseEnum({
125
+ * value: {
126
+ * type: 'boolean',
127
+ * enum: [true, false],
128
+ * description: 'Explicit boolean enum'
129
+ * },
130
+ * nullable: false,
131
+ * valibotSchema: v.boolean(),
132
+ * context: parseContext
133
+ * });
134
+ *
135
+ * console.log(result.enum); // [true, false]
136
+ * ```
137
+ */
14
138
  export declare const parseEnum: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseEnumArgs<T, Nullable, Value>) => ParseEnumReturn<T, Nullable, Value>;
15
139
  export {};
16
140
  //# sourceMappingURL=parseEnum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseEnum.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseEnum.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,aAAa,CAChB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY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,QAAQ,CAAA;IAClB,gDAAgD;IAChD,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;GAMG;AACH,KAAK,eAAe,CAClB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,0CAA0C;IAC1C,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,GAAG,SAAS,CAAA;IACxE,6DAA6D;IAC7D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,CAAA;CACxC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AACH,eAAO,MAAM,SAAS,GACpB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,6CAKC,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAG,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAgBxE,CAAA"}
@@ -1,4 +1,108 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema enum values with type safety.
4
+ *
5
+ * This function extracts and validates enum arrays from OpenAPI schema objects,
6
+ * ensuring all enum values conform to the expected type and handling nullable
7
+ * schemas correctly. Invalid enum values are removed and logged as warnings
8
+ * through the parse context.
9
+ *
10
+ * The function provides full type safety, with the return type reflecting whether
11
+ * null values are allowed in the enum array based on the nullable parameter.
12
+ *
13
+ * @template T - The expected type of enum values
14
+ * @template Nullable - Whether the schema allows null values in enums
15
+ * @template Value - The OpenAPI schema object type
16
+ *
17
+ * @param args - Parsing configuration
18
+ * @returns Parsed enum data with the validated enum array and cleaned schema
19
+ *
20
+ * @example Basic string enum parsing
21
+ * ```typescript
22
+ * import { parseEnum } from '@skmtc/core/oas/_helpers';
23
+ * import * as v from 'valibot';
24
+ *
25
+ * const result = parseEnum({
26
+ * value: {
27
+ * type: 'string',
28
+ * enum: ['active', 'inactive', 'pending'],
29
+ * description: 'User status'
30
+ * },
31
+ * nullable: false,
32
+ * valibotSchema: v.string(),
33
+ * context: parseContext
34
+ * });
35
+ *
36
+ * console.log(result.enum); // ['active', 'inactive', 'pending']
37
+ * console.log(result.value); // { type: 'string', description: 'User status' }
38
+ * ```
39
+ *
40
+ * @example Nullable enum parsing
41
+ * ```typescript
42
+ * const result = parseEnum({
43
+ * value: {
44
+ * type: 'string',
45
+ * enum: ['red', 'green', 'blue', null],
46
+ * description: 'Optional color selection'
47
+ * },
48
+ * nullable: true,
49
+ * valibotSchema: v.string(),
50
+ * context: parseContext
51
+ * });
52
+ *
53
+ * console.log(result.enum); // ['red', 'green', 'blue', null]
54
+ * // Type: (string | null)[] | undefined
55
+ * ```
56
+ *
57
+ * @example Number enum parsing
58
+ * ```typescript
59
+ * const result = parseEnum({
60
+ * value: {
61
+ * type: 'number',
62
+ * enum: [1, 2, 3, 5, 8, 13],
63
+ * description: 'Fibonacci subset'
64
+ * },
65
+ * nullable: false,
66
+ * valibotSchema: v.number(),
67
+ * context: parseContext
68
+ * });
69
+ *
70
+ * console.log(result.enum); // [1, 2, 3, 5, 8, 13]
71
+ * ```
72
+ *
73
+ * @example Invalid enum handling
74
+ * ```typescript
75
+ * const result = parseEnum({
76
+ * value: {
77
+ * type: 'number',
78
+ * enum: [1, 'invalid', 3], // Contains invalid value
79
+ * description: 'Mixed enum (invalid)'
80
+ * },
81
+ * nullable: false,
82
+ * valibotSchema: v.number(),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.enum); // undefined (entire enum removed due to invalid value)
87
+ * // Context will log a warning about the invalid enum
88
+ * ```
89
+ *
90
+ * @example Boolean enum (essentially optional boolean)
91
+ * ```typescript
92
+ * const result = parseEnum({
93
+ * value: {
94
+ * type: 'boolean',
95
+ * enum: [true, false],
96
+ * description: 'Explicit boolean enum'
97
+ * },
98
+ * nullable: false,
99
+ * valibotSchema: v.boolean(),
100
+ * context: parseContext
101
+ * });
102
+ *
103
+ * console.log(result.enum); // [true, false]
104
+ * ```
105
+ */
2
106
  export const parseEnum = ({ value, nullable, valibotSchema, context }) => {
3
107
  const { enum: enums, ...rest } = value;
4
108
  const parsedEnum = context.provisionalParse({
@@ -1,16 +1,123 @@
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 examples.
6
+ *
7
+ * @template T - The expected type of the example value
8
+ * @template Nullable - Whether the schema allows null values
9
+ * @template Value - The OpenAPI schema object type
10
+ */
4
11
  type ParseExampleArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
12
+ /** The OpenAPI schema object without nullable property */
5
13
  value: Omit<Value, 'nullable'>;
14
+ /** Whether the schema allows null values */
6
15
  nullable: Nullable;
16
+ /** Valibot schema for validating the example */
7
17
  valibotSchema: v.GenericSchema<T>;
18
+ /** Parse context for error handling */
8
19
  context: ParseContext;
9
20
  };
21
+ /**
22
+ * Return type for parsed example data.
23
+ *
24
+ * @template T - The expected type of the example value
25
+ * @template Nullable - Whether the schema allows null values
26
+ * @template Value - The OpenAPI schema object type
27
+ */
10
28
  type ParseExampleReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
29
+ /** The parsed and validated example value */
11
30
  example: Nullable extends true ? T | null | undefined : T | undefined;
31
+ /** The schema object without example and nullable properties */
12
32
  value: Omit<Value, 'nullable' | 'example'>;
13
33
  };
34
+ /**
35
+ * Parses and validates OpenAPI schema examples with type safety.
36
+ *
37
+ * This function extracts and validates example values from OpenAPI schema objects,
38
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
39
+ * Invalid examples are removed and logged as warnings through the parse context.
40
+ *
41
+ * The function provides full type safety, with the return type reflecting whether
42
+ * null values are allowed based on the nullable parameter.
43
+ *
44
+ * @template T - The expected type of the example value
45
+ * @template Nullable - Whether the schema allows null values
46
+ * @template Value - The OpenAPI schema object type
47
+ *
48
+ * @param args - Parsing configuration
49
+ * @returns Parsed example data with the validated example and cleaned schema
50
+ *
51
+ * @example Basic string example parsing
52
+ * ```typescript
53
+ * import { parseExample } from '@skmtc/core/oas/_helpers';
54
+ * import * as v from 'valibot';
55
+ *
56
+ * const result = parseExample({
57
+ * value: {
58
+ * type: 'string',
59
+ * example: 'hello world',
60
+ * format: 'text'
61
+ * },
62
+ * nullable: false,
63
+ * valibotSchema: v.string(),
64
+ * context: parseContext
65
+ * });
66
+ *
67
+ * console.log(result.example); // 'hello world'
68
+ * console.log(result.value); // { type: 'string', format: 'text' }
69
+ * ```
70
+ *
71
+ * @example Nullable schema example
72
+ * ```typescript
73
+ * const result = parseExample({
74
+ * value: {
75
+ * type: 'string',
76
+ * example: null,
77
+ * minLength: 1
78
+ * },
79
+ * nullable: true,
80
+ * valibotSchema: v.string(),
81
+ * context: parseContext
82
+ * });
83
+ *
84
+ * console.log(result.example); // null (valid for nullable schema)
85
+ * // Type: string | null | undefined
86
+ * ```
87
+ *
88
+ * @example Invalid example handling
89
+ * ```typescript
90
+ * const result = parseExample({
91
+ * value: {
92
+ * type: 'number',
93
+ * example: 'not a number', // Invalid example
94
+ * minimum: 0
95
+ * },
96
+ * nullable: false,
97
+ * valibotSchema: v.number(),
98
+ * context: parseContext
99
+ * });
100
+ *
101
+ * console.log(result.example); // undefined (invalid example removed)
102
+ * // Context will log a warning about the invalid example
103
+ * ```
104
+ *
105
+ * @example Array example parsing
106
+ * ```typescript
107
+ * const result = parseExample({
108
+ * value: {
109
+ * type: 'array',
110
+ * items: { type: 'string' },
111
+ * example: ['item1', 'item2', 'item3']
112
+ * },
113
+ * nullable: false,
114
+ * valibotSchema: v.array(v.string()),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.example); // ['item1', 'item2', 'item3']
119
+ * ```
120
+ */
14
121
  export declare const parseExample: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseExampleArgs<T, Nullable, Value>) => ParseExampleReturn<T, Nullable, Value>;
15
122
  export {};
16
123
  //# sourceMappingURL=parseExample.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseExample.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseExample.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,gBAAgB,CACnB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC9B,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,KAAK,kBAAkB,CACrB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAA;IACrE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CAC3C,CAAA;AAED,eAAO,MAAM,YAAY,GAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,eAAO,MAAM,YAAY,GACvB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,6CAKC,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAG,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAgB9E,CAAA"}
@@ -1,4 +1,91 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema examples with type safety.
4
+ *
5
+ * This function extracts and validates example values from OpenAPI schema objects,
6
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
7
+ * Invalid examples are removed and logged as warnings through the parse context.
8
+ *
9
+ * The function provides full type safety, with the return type reflecting whether
10
+ * null values are allowed based on the nullable parameter.
11
+ *
12
+ * @template T - The expected type of the example value
13
+ * @template Nullable - Whether the schema allows null values
14
+ * @template Value - The OpenAPI schema object type
15
+ *
16
+ * @param args - Parsing configuration
17
+ * @returns Parsed example data with the validated example and cleaned schema
18
+ *
19
+ * @example Basic string example parsing
20
+ * ```typescript
21
+ * import { parseExample } from '@skmtc/core/oas/_helpers';
22
+ * import * as v from 'valibot';
23
+ *
24
+ * const result = parseExample({
25
+ * value: {
26
+ * type: 'string',
27
+ * example: 'hello world',
28
+ * format: 'text'
29
+ * },
30
+ * nullable: false,
31
+ * valibotSchema: v.string(),
32
+ * context: parseContext
33
+ * });
34
+ *
35
+ * console.log(result.example); // 'hello world'
36
+ * console.log(result.value); // { type: 'string', format: 'text' }
37
+ * ```
38
+ *
39
+ * @example Nullable schema example
40
+ * ```typescript
41
+ * const result = parseExample({
42
+ * value: {
43
+ * type: 'string',
44
+ * example: null,
45
+ * minLength: 1
46
+ * },
47
+ * nullable: true,
48
+ * valibotSchema: v.string(),
49
+ * context: parseContext
50
+ * });
51
+ *
52
+ * console.log(result.example); // null (valid for nullable schema)
53
+ * // Type: string | null | undefined
54
+ * ```
55
+ *
56
+ * @example Invalid example handling
57
+ * ```typescript
58
+ * const result = parseExample({
59
+ * value: {
60
+ * type: 'number',
61
+ * example: 'not a number', // Invalid example
62
+ * minimum: 0
63
+ * },
64
+ * nullable: false,
65
+ * valibotSchema: v.number(),
66
+ * context: parseContext
67
+ * });
68
+ *
69
+ * console.log(result.example); // undefined (invalid example removed)
70
+ * // Context will log a warning about the invalid example
71
+ * ```
72
+ *
73
+ * @example Array example parsing
74
+ * ```typescript
75
+ * const result = parseExample({
76
+ * value: {
77
+ * type: 'array',
78
+ * items: { type: 'string' },
79
+ * example: ['item1', 'item2', 'item3']
80
+ * },
81
+ * nullable: false,
82
+ * valibotSchema: v.array(v.string()),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.example); // ['item1', 'item2', 'item3']
87
+ * ```
88
+ */
2
89
  export const parseExample = ({ value, nullable, valibotSchema, context }) => {
3
90
  const { example, ...rest } = value;
4
91
  const parsedExample = context.provisionalParse({