@skmtc/core 0.0.796 → 0.0.798
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.
- package/esm/app/validate.d.ts +32 -0
- package/esm/app/validate.d.ts.map +1 -1
- package/esm/app/validate.js +32 -0
- package/esm/context/CoreContext.d.ts +147 -2
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +87 -0
- package/esm/context/GenerateContext.d.ts +180 -0
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +25 -0
- package/esm/context/ParseContext.d.ts +6 -0
- package/esm/context/ParseContext.d.ts.map +1 -1
- package/esm/context/ParseContext.js +6 -0
- package/esm/dsl/constants.d.ts +28 -0
- package/esm/dsl/constants.d.ts.map +1 -1
- package/esm/dsl/constants.js +28 -0
- package/esm/oas/_helpers/parseDefault.d.ts +148 -0
- package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
- package/esm/oas/_helpers/parseDefault.js +128 -0
- package/esm/oas/_helpers/parseEnum.d.ts +124 -0
- package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
- package/esm/oas/_helpers/parseEnum.js +104 -0
- package/esm/oas/_helpers/parseExample.d.ts +107 -0
- package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
- package/esm/oas/_helpers/parseExample.js +87 -0
- package/esm/oas/_helpers/parseFormat.d.ts +154 -0
- package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
- package/esm/oas/_helpers/parseFormat.js +138 -0
- package/esm/oas/_helpers/parseNullable.d.ts +127 -0
- package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
- package/esm/oas/_helpers/parseNullable.js +113 -0
- package/esm/oas/example/toExamplesV3.d.ts +39 -0
- package/esm/oas/example/toExamplesV3.d.ts.map +1 -1
- package/esm/oas/example/toExamplesV3.js +29 -0
- package/esm/oas/object/Object.d.ts +6 -0
- package/esm/oas/object/Object.d.ts.map +1 -1
- package/esm/oas/object/Object.js +6 -0
- package/esm/oas/operation/Operation.d.ts +34 -0
- package/esm/oas/operation/Operation.d.ts.map +1 -1
- package/esm/oas/operation/Operation.js +14 -0
- package/esm/oas/parameter/Parameter.d.ts +3 -0
- package/esm/oas/parameter/Parameter.d.ts.map +1 -1
- package/esm/oas/parameter/Parameter.js +3 -0
- package/esm/oas/ref/ref-types.d.ts +42 -0
- package/esm/oas/ref/ref-types.d.ts.map +1 -1
- package/esm/oas/ref/ref-types.js +9 -0
- package/esm/oas/securitySchemes/security-scheme-types.d.ts +63 -0
- package/esm/oas/securitySchemes/security-scheme-types.d.ts.map +1 -1
- package/esm/oas/securitySchemes/security-scheme-types.js +15 -0
- package/esm/run/toV3JsonDocument.d.ts +90 -0
- package/esm/run/toV3JsonDocument.d.ts.map +1 -1
- package/esm/run/toV3JsonDocument.js +84 -0
- package/esm/types/Results.d.ts +32 -0
- package/esm/types/Results.d.ts.map +1 -1
- package/esm/types/Results.js +12 -0
- package/package.json +1 -1
- package/script/app/validate.d.ts +32 -0
- package/script/app/validate.d.ts.map +1 -1
- package/script/app/validate.js +32 -0
- package/script/context/CoreContext.d.ts +147 -2
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +87 -0
- package/script/context/GenerateContext.d.ts +180 -0
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +25 -0
- package/script/context/ParseContext.d.ts +6 -0
- package/script/context/ParseContext.d.ts.map +1 -1
- package/script/context/ParseContext.js +6 -0
- package/script/dsl/constants.d.ts +28 -0
- package/script/dsl/constants.d.ts.map +1 -1
- package/script/dsl/constants.js +28 -0
- package/script/oas/_helpers/parseDefault.d.ts +148 -0
- package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
- package/script/oas/_helpers/parseDefault.js +128 -0
- package/script/oas/_helpers/parseEnum.d.ts +124 -0
- package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
- package/script/oas/_helpers/parseEnum.js +104 -0
- package/script/oas/_helpers/parseExample.d.ts +107 -0
- package/script/oas/_helpers/parseExample.d.ts.map +1 -1
- package/script/oas/_helpers/parseExample.js +87 -0
- package/script/oas/_helpers/parseFormat.d.ts +154 -0
- package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
- package/script/oas/_helpers/parseFormat.js +138 -0
- package/script/oas/_helpers/parseNullable.d.ts +127 -0
- package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
- package/script/oas/_helpers/parseNullable.js +113 -0
- package/script/oas/example/toExamplesV3.d.ts +39 -0
- package/script/oas/example/toExamplesV3.d.ts.map +1 -1
- package/script/oas/example/toExamplesV3.js +29 -0
- package/script/oas/object/Object.d.ts +6 -0
- package/script/oas/object/Object.d.ts.map +1 -1
- package/script/oas/object/Object.js +6 -0
- package/script/oas/operation/Operation.d.ts +34 -0
- package/script/oas/operation/Operation.d.ts.map +1 -1
- package/script/oas/operation/Operation.js +14 -0
- package/script/oas/parameter/Parameter.d.ts +3 -0
- package/script/oas/parameter/Parameter.d.ts.map +1 -1
- package/script/oas/parameter/Parameter.js +3 -0
- package/script/oas/ref/ref-types.d.ts +42 -0
- package/script/oas/ref/ref-types.d.ts.map +1 -1
- package/script/oas/ref/ref-types.js +9 -0
- package/script/oas/securitySchemes/security-scheme-types.d.ts +63 -0
- package/script/oas/securitySchemes/security-scheme-types.d.ts.map +1 -1
- package/script/oas/securitySchemes/security-scheme-types.js +15 -0
- package/script/run/toV3JsonDocument.d.ts +90 -0
- package/script/run/toV3JsonDocument.d.ts.map +1 -1
- package/script/run/toV3JsonDocument.js +84 -0
- package/script/types/Results.d.ts +32 -0
- package/script/types/Results.d.ts.map +1 -1
- package/script/types/Results.js +12 -0
|
@@ -1,16 +1,164 @@
|
|
|
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 default values.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The expected type of the default value
|
|
8
|
+
* @template Nullable - Whether the schema allows null values
|
|
9
|
+
* @template Value - The OpenAPI schema object type
|
|
10
|
+
*/
|
|
4
11
|
type ParseDefaultArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
|
|
12
|
+
/** The OpenAPI schema object without nullable, example, and enum properties */
|
|
5
13
|
value: Omit<Value, 'nullable' | 'example' | 'enum'>;
|
|
14
|
+
/** Whether the schema allows null values */
|
|
6
15
|
nullable: Nullable;
|
|
16
|
+
/** Valibot schema for validating the default value */
|
|
7
17
|
valibotSchema: v.GenericSchema<T>;
|
|
18
|
+
/** Parse context for error handling */
|
|
8
19
|
context: ParseContext;
|
|
9
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Return type for parsed default value data.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The expected type of the default value
|
|
25
|
+
* @template Nullable - Whether the schema allows null values
|
|
26
|
+
* @template Value - The OpenAPI schema object type
|
|
27
|
+
*/
|
|
10
28
|
type ParseDefaultReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
|
|
29
|
+
/** The parsed and validated default value */
|
|
11
30
|
default: Nullable extends true ? T | null | undefined : T | undefined;
|
|
31
|
+
/** The schema object with all processed properties removed */
|
|
12
32
|
value: Omit<Value, 'nullable' | 'example' | 'enum' | 'default'>;
|
|
13
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Parses and validates OpenAPI schema default values with type safety.
|
|
36
|
+
*
|
|
37
|
+
* This function extracts and validates default values from OpenAPI schema objects,
|
|
38
|
+
* ensuring they conform to the expected type and handling nullable schemas correctly.
|
|
39
|
+
* Invalid default values 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. This ensures that
|
|
43
|
+
* generated code maintains proper type constraints for default values.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The expected type of the default value
|
|
46
|
+
* @template Nullable - Whether the schema allows null as a default
|
|
47
|
+
* @template Value - The OpenAPI schema object type
|
|
48
|
+
*
|
|
49
|
+
* @param args - Parsing configuration
|
|
50
|
+
* @returns Parsed default data with the validated default value and cleaned schema
|
|
51
|
+
*
|
|
52
|
+
* @example Basic string default parsing
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { parseDefault } from '@skmtc/core/oas/_helpers';
|
|
55
|
+
* import * as v from 'valibot';
|
|
56
|
+
*
|
|
57
|
+
* const result = parseDefault({
|
|
58
|
+
* value: {
|
|
59
|
+
* type: 'string',
|
|
60
|
+
* default: 'hello world',
|
|
61
|
+
* minLength: 5
|
|
62
|
+
* },
|
|
63
|
+
* nullable: false,
|
|
64
|
+
* valibotSchema: v.string(),
|
|
65
|
+
* context: parseContext
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* console.log(result.default); // 'hello world'
|
|
69
|
+
* console.log(result.value); // { type: 'string', minLength: 5 }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Nullable default value
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const result = parseDefault({
|
|
75
|
+
* value: {
|
|
76
|
+
* type: 'string',
|
|
77
|
+
* default: null,
|
|
78
|
+
* format: 'email'
|
|
79
|
+
* },
|
|
80
|
+
* nullable: true,
|
|
81
|
+
* valibotSchema: v.string(),
|
|
82
|
+
* context: parseContext
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* console.log(result.default); // null (valid for nullable schema)
|
|
86
|
+
* // Type: string | null | undefined
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Number default with constraints
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const result = parseDefault({
|
|
92
|
+
* value: {
|
|
93
|
+
* type: 'number',
|
|
94
|
+
* default: 42,
|
|
95
|
+
* minimum: 0,
|
|
96
|
+
* maximum: 100
|
|
97
|
+
* },
|
|
98
|
+
* nullable: false,
|
|
99
|
+
* valibotSchema: v.number(),
|
|
100
|
+
* context: parseContext
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* console.log(result.default); // 42
|
|
104
|
+
* console.log(result.value); // { type: 'number', minimum: 0, maximum: 100 }
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example Invalid default handling
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const result = parseDefault({
|
|
110
|
+
* value: {
|
|
111
|
+
* type: 'boolean',
|
|
112
|
+
* default: 'not a boolean', // Invalid default
|
|
113
|
+
* description: 'A boolean flag'
|
|
114
|
+
* },
|
|
115
|
+
* nullable: false,
|
|
116
|
+
* valibotSchema: v.boolean(),
|
|
117
|
+
* context: parseContext
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* console.log(result.default); // undefined (invalid default removed)
|
|
121
|
+
* // Context will log a warning about the invalid default
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example Array default value
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const result = parseDefault({
|
|
127
|
+
* value: {
|
|
128
|
+
* type: 'array',
|
|
129
|
+
* items: { type: 'string' },
|
|
130
|
+
* default: ['item1', 'item2']
|
|
131
|
+
* },
|
|
132
|
+
* nullable: false,
|
|
133
|
+
* valibotSchema: v.array(v.string()),
|
|
134
|
+
* context: parseContext
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* console.log(result.default); // ['item1', 'item2']
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Object default value
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const result = parseDefault({
|
|
143
|
+
* value: {
|
|
144
|
+
* type: 'object',
|
|
145
|
+
* properties: {
|
|
146
|
+
* name: { type: 'string' },
|
|
147
|
+
* age: { type: 'number' }
|
|
148
|
+
* },
|
|
149
|
+
* default: { name: 'John', age: 30 }
|
|
150
|
+
* },
|
|
151
|
+
* nullable: false,
|
|
152
|
+
* valibotSchema: v.object({
|
|
153
|
+
* name: v.string(),
|
|
154
|
+
* age: v.number()
|
|
155
|
+
* }),
|
|
156
|
+
* context: parseContext
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* console.log(result.default); // { name: 'John', age: 30 }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
14
162
|
export declare const parseDefault: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseDefaultArgs<T, Nullable, Value>) => ParseDefaultReturn<T, Nullable, Value>;
|
|
15
163
|
export {};
|
|
16
164
|
//# sourceMappingURL=parseDefault.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDefault.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseDefault.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,GAAG,SAAS,GAAG,MAAM,CAAC,CAAA;IACnD,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,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;CAChE,CAAA;AAED,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
|
+
{"version":3,"file":"parseDefault.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseDefault.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;;;;;;GAMG;AACH,KAAK,gBAAgB,CACnB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,+EAA+E;IAC/E,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC,CAAA;IACnD,4CAA4C;IAC5C,QAAQ,EAAE,QAAQ,CAAA;IAClB,sDAAsD;IACtD,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;GAMG;AACH,KAAK,kBAAkB,CACrB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,6CAA6C;IAC7C,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAA;IACrE,8DAA8D;IAC9D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;CAChE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+HG;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"}
|
|
@@ -35,6 +35,134 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.parseDefault = void 0;
|
|
37
37
|
const v = __importStar(require("valibot"));
|
|
38
|
+
/**
|
|
39
|
+
* Parses and validates OpenAPI schema default values with type safety.
|
|
40
|
+
*
|
|
41
|
+
* This function extracts and validates default values from OpenAPI schema objects,
|
|
42
|
+
* ensuring they conform to the expected type and handling nullable schemas correctly.
|
|
43
|
+
* Invalid default values are removed and logged as warnings through the parse context.
|
|
44
|
+
*
|
|
45
|
+
* The function provides full type safety, with the return type reflecting whether
|
|
46
|
+
* null values are allowed based on the nullable parameter. This ensures that
|
|
47
|
+
* generated code maintains proper type constraints for default values.
|
|
48
|
+
*
|
|
49
|
+
* @template T - The expected type of the default value
|
|
50
|
+
* @template Nullable - Whether the schema allows null as a default
|
|
51
|
+
* @template Value - The OpenAPI schema object type
|
|
52
|
+
*
|
|
53
|
+
* @param args - Parsing configuration
|
|
54
|
+
* @returns Parsed default data with the validated default value and cleaned schema
|
|
55
|
+
*
|
|
56
|
+
* @example Basic string default parsing
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { parseDefault } from '@skmtc/core/oas/_helpers';
|
|
59
|
+
* import * as v from 'valibot';
|
|
60
|
+
*
|
|
61
|
+
* const result = parseDefault({
|
|
62
|
+
* value: {
|
|
63
|
+
* type: 'string',
|
|
64
|
+
* default: 'hello world',
|
|
65
|
+
* minLength: 5
|
|
66
|
+
* },
|
|
67
|
+
* nullable: false,
|
|
68
|
+
* valibotSchema: v.string(),
|
|
69
|
+
* context: parseContext
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* console.log(result.default); // 'hello world'
|
|
73
|
+
* console.log(result.value); // { type: 'string', minLength: 5 }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example Nullable default value
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const result = parseDefault({
|
|
79
|
+
* value: {
|
|
80
|
+
* type: 'string',
|
|
81
|
+
* default: null,
|
|
82
|
+
* format: 'email'
|
|
83
|
+
* },
|
|
84
|
+
* nullable: true,
|
|
85
|
+
* valibotSchema: v.string(),
|
|
86
|
+
* context: parseContext
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* console.log(result.default); // null (valid for nullable schema)
|
|
90
|
+
* // Type: string | null | undefined
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Number default with constraints
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const result = parseDefault({
|
|
96
|
+
* value: {
|
|
97
|
+
* type: 'number',
|
|
98
|
+
* default: 42,
|
|
99
|
+
* minimum: 0,
|
|
100
|
+
* maximum: 100
|
|
101
|
+
* },
|
|
102
|
+
* nullable: false,
|
|
103
|
+
* valibotSchema: v.number(),
|
|
104
|
+
* context: parseContext
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* console.log(result.default); // 42
|
|
108
|
+
* console.log(result.value); // { type: 'number', minimum: 0, maximum: 100 }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example Invalid default handling
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const result = parseDefault({
|
|
114
|
+
* value: {
|
|
115
|
+
* type: 'boolean',
|
|
116
|
+
* default: 'not a boolean', // Invalid default
|
|
117
|
+
* description: 'A boolean flag'
|
|
118
|
+
* },
|
|
119
|
+
* nullable: false,
|
|
120
|
+
* valibotSchema: v.boolean(),
|
|
121
|
+
* context: parseContext
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* console.log(result.default); // undefined (invalid default removed)
|
|
125
|
+
* // Context will log a warning about the invalid default
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example Array default value
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const result = parseDefault({
|
|
131
|
+
* value: {
|
|
132
|
+
* type: 'array',
|
|
133
|
+
* items: { type: 'string' },
|
|
134
|
+
* default: ['item1', 'item2']
|
|
135
|
+
* },
|
|
136
|
+
* nullable: false,
|
|
137
|
+
* valibotSchema: v.array(v.string()),
|
|
138
|
+
* context: parseContext
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* console.log(result.default); // ['item1', 'item2']
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example Object default value
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const result = parseDefault({
|
|
147
|
+
* value: {
|
|
148
|
+
* type: 'object',
|
|
149
|
+
* properties: {
|
|
150
|
+
* name: { type: 'string' },
|
|
151
|
+
* age: { type: 'number' }
|
|
152
|
+
* },
|
|
153
|
+
* default: { name: 'John', age: 30 }
|
|
154
|
+
* },
|
|
155
|
+
* nullable: false,
|
|
156
|
+
* valibotSchema: v.object({
|
|
157
|
+
* name: v.string(),
|
|
158
|
+
* age: v.number()
|
|
159
|
+
* }),
|
|
160
|
+
* context: parseContext
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* console.log(result.default); // { name: 'John', age: 30 }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
38
166
|
const parseDefault = ({ value, nullable, valibotSchema, context }) => {
|
|
39
167
|
const { default: defaultValue, ...rest } = value;
|
|
40
168
|
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,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,eAAe,CAClB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,GAAG,SAAS,CAAA;IACxE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,CAAA;CACxC,CAAA;AAED,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
|
+
{"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;;;;;;GAMG;AACH,KAAK,aAAa,CAChB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,0DAA0D;IAC1D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC9B,4CAA4C;IAC5C,QAAQ,EAAE,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"}
|
|
@@ -35,6 +35,110 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.parseEnum = void 0;
|
|
37
37
|
const v = __importStar(require("valibot"));
|
|
38
|
+
/**
|
|
39
|
+
* Parses and validates OpenAPI schema enum values with type safety.
|
|
40
|
+
*
|
|
41
|
+
* This function extracts and validates enum arrays from OpenAPI schema objects,
|
|
42
|
+
* ensuring all enum values conform to the expected type and handling nullable
|
|
43
|
+
* schemas correctly. Invalid enum values are removed and logged as warnings
|
|
44
|
+
* through the parse context.
|
|
45
|
+
*
|
|
46
|
+
* The function provides full type safety, with the return type reflecting whether
|
|
47
|
+
* null values are allowed in the enum array based on the nullable parameter.
|
|
48
|
+
*
|
|
49
|
+
* @template T - The expected type of enum values
|
|
50
|
+
* @template Nullable - Whether the schema allows null values in enums
|
|
51
|
+
* @template Value - The OpenAPI schema object type
|
|
52
|
+
*
|
|
53
|
+
* @param args - Parsing configuration
|
|
54
|
+
* @returns Parsed enum data with the validated enum array and cleaned schema
|
|
55
|
+
*
|
|
56
|
+
* @example Basic string enum parsing
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { parseEnum } from '@skmtc/core/oas/_helpers';
|
|
59
|
+
* import * as v from 'valibot';
|
|
60
|
+
*
|
|
61
|
+
* const result = parseEnum({
|
|
62
|
+
* value: {
|
|
63
|
+
* type: 'string',
|
|
64
|
+
* enum: ['active', 'inactive', 'pending'],
|
|
65
|
+
* description: 'User status'
|
|
66
|
+
* },
|
|
67
|
+
* nullable: false,
|
|
68
|
+
* valibotSchema: v.string(),
|
|
69
|
+
* context: parseContext
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* console.log(result.enum); // ['active', 'inactive', 'pending']
|
|
73
|
+
* console.log(result.value); // { type: 'string', description: 'User status' }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example Nullable enum parsing
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const result = parseEnum({
|
|
79
|
+
* value: {
|
|
80
|
+
* type: 'string',
|
|
81
|
+
* enum: ['red', 'green', 'blue', null],
|
|
82
|
+
* description: 'Optional color selection'
|
|
83
|
+
* },
|
|
84
|
+
* nullable: true,
|
|
85
|
+
* valibotSchema: v.string(),
|
|
86
|
+
* context: parseContext
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* console.log(result.enum); // ['red', 'green', 'blue', null]
|
|
90
|
+
* // Type: (string | null)[] | undefined
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Number enum parsing
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const result = parseEnum({
|
|
96
|
+
* value: {
|
|
97
|
+
* type: 'number',
|
|
98
|
+
* enum: [1, 2, 3, 5, 8, 13],
|
|
99
|
+
* description: 'Fibonacci subset'
|
|
100
|
+
* },
|
|
101
|
+
* nullable: false,
|
|
102
|
+
* valibotSchema: v.number(),
|
|
103
|
+
* context: parseContext
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* console.log(result.enum); // [1, 2, 3, 5, 8, 13]
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Invalid enum handling
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = parseEnum({
|
|
112
|
+
* value: {
|
|
113
|
+
* type: 'number',
|
|
114
|
+
* enum: [1, 'invalid', 3], // Contains invalid value
|
|
115
|
+
* description: 'Mixed enum (invalid)'
|
|
116
|
+
* },
|
|
117
|
+
* nullable: false,
|
|
118
|
+
* valibotSchema: v.number(),
|
|
119
|
+
* context: parseContext
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* console.log(result.enum); // undefined (entire enum removed due to invalid value)
|
|
123
|
+
* // Context will log a warning about the invalid enum
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example Boolean enum (essentially optional boolean)
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const result = parseEnum({
|
|
129
|
+
* value: {
|
|
130
|
+
* type: 'boolean',
|
|
131
|
+
* enum: [true, false],
|
|
132
|
+
* description: 'Explicit boolean enum'
|
|
133
|
+
* },
|
|
134
|
+
* nullable: false,
|
|
135
|
+
* valibotSchema: v.boolean(),
|
|
136
|
+
* context: parseContext
|
|
137
|
+
* });
|
|
138
|
+
*
|
|
139
|
+
* console.log(result.enum); // [true, false]
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
38
142
|
const parseEnum = ({ value, nullable, valibotSchema, context }) => {
|
|
39
143
|
const { enum: enums, ...rest } = value;
|
|
40
144
|
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
|