@kubb/plugin-valibot 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/index.cjs +2105 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +308 -0
- package/dist/index.d.ts +308 -0
- package/dist/index.js +2096 -0
- package/dist/index.js.map +1 -0
- package/docs/guides/coercion.md +52 -0
- package/docs/guides/customization.md +131 -0
- package/docs/guides/format-mappings.md +98 -0
- package/docs/guides/inferred-types.md +70 -0
- package/docs/options.md +215 -0
- package/docs/overview.md +70 -0
- package/kubb-extension.json +224 -0
- package/package.json +93 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
+
/**
|
|
3
|
+
* Partial map of node-type overrides for the Valibot printer, keyed by `SchemaType`. Each function
|
|
4
|
+
* replaces the built-in handler and can call `this.transform`, `this.base`, and `this.options`.
|
|
5
|
+
*/
|
|
6
|
+
type PrinterValibotNodes = ast.PrinterPartial<string, PrinterValibotOptions>;
|
|
7
|
+
type PrinterValibotOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Output form for an OpenAPI `pattern` inside `v.regex(...)`.
|
|
10
|
+
*
|
|
11
|
+
* @default 'literal'
|
|
12
|
+
*/
|
|
13
|
+
regexType?: PluginValibot['resolvedOptions']['regexType'];
|
|
14
|
+
/**
|
|
15
|
+
* How a `oneOf` without a discriminator is validated: strict members, or exactly one match.
|
|
16
|
+
*
|
|
17
|
+
* @default 'union'
|
|
18
|
+
*/
|
|
19
|
+
oneOfType?: PluginValibot['resolvedOptions']['oneOfType'];
|
|
20
|
+
/**
|
|
21
|
+
* Convert input before validation: `v.toString()`, `v.toNumber()`, and `v.toDate()`.
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
coercion?: PluginValibot['resolvedOptions']['coercion'];
|
|
26
|
+
/**
|
|
27
|
+
* Which way a node converts between its wire type and its runtime type:
|
|
28
|
+
* - `'decode'` (default): wire into runtime, used by response schemas.
|
|
29
|
+
* - `'encode'`: runtime back to wire, used by request bodies and parameters.
|
|
30
|
+
*
|
|
31
|
+
* A handler that returns different output per direction makes the generator emit an
|
|
32
|
+
* `${name}InputSchema` variant for that component.
|
|
33
|
+
*/
|
|
34
|
+
direction?: 'encode' | 'decode';
|
|
35
|
+
/**
|
|
36
|
+
* The adapter's `dateType`. `'stringLocal'` drops the timestamp check, because Valibot has no
|
|
37
|
+
* check for a date-time without an offset.
|
|
38
|
+
*/
|
|
39
|
+
dateType?: ast.ParserOptions['dateType'];
|
|
40
|
+
/**
|
|
41
|
+
* Turns a schema name from the spec into the name of its generated const.
|
|
42
|
+
*/
|
|
43
|
+
resolver?: ResolverValibot;
|
|
44
|
+
/**
|
|
45
|
+
* Property names to drop from the printed object with `v.omit(...)`.
|
|
46
|
+
*/
|
|
47
|
+
keysToOmit?: Array<string> | null;
|
|
48
|
+
/**
|
|
49
|
+
* Schema names that are part of a circular reference. A `$ref` to one of them prints inside
|
|
50
|
+
* `v.lazy(() => ...)`.
|
|
51
|
+
*/
|
|
52
|
+
cyclicSchemas?: ReadonlySet<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Custom handler map for node type overrides.
|
|
55
|
+
*/
|
|
56
|
+
nodes?: PrinterValibotNodes;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Factory options for the Valibot printer: its name, options, and output types.
|
|
60
|
+
*/
|
|
61
|
+
type PrinterValibotFactory = ast.PrinterFactoryOptions<'valibot', PrinterValibotOptions, string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Valibot v1 printer. Turns a `SchemaNode` into the code of a Valibot schema.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const printer = printerValibot({})
|
|
68
|
+
*
|
|
69
|
+
* printer.print(ast.factory.createSchema({ type: 'string', min: 1 })) // 'v.pipe(v.string(), v.minLength(1))'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const printerValibot: (options?: PrinterValibotOptions | undefined) => ast.Printer<PrinterValibotFactory>;
|
|
73
|
+
/**
|
|
74
|
+
* The names the plugin gives to generated schemas and their inferred types.
|
|
75
|
+
*/
|
|
76
|
+
type ResolverValibot = Resolver & {
|
|
77
|
+
schema: {
|
|
78
|
+
/**
|
|
79
|
+
* The inferred type name of a component schema.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* resolver.schema.typeName('pet') // 'PetSchemaType'
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
typeName(name: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* The inferred type name of an operation schema, which already ends in `Schema`.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* resolver.schema.type('addPetBodySchema') // 'AddPetBodySchemaType'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
type(name: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* The name of the request variant of a component schema, which encodes where the schema decodes.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* resolver.schema.inputName('pet') // 'petInputSchema'
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
inputName(name: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* The inferred type name of the request variant.
|
|
107
|
+
*/
|
|
108
|
+
inputTypeName(name: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* The name of the type guard of a component schema.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* resolver.schema.isName('pet') // 'isPet'
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
isName(name: string): string;
|
|
118
|
+
/**
|
|
119
|
+
* The name of the assertion function of a component schema.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* resolver.schema.assertName('pet') // 'assertPet'
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
assertName(name: string): string;
|
|
127
|
+
};
|
|
128
|
+
param: {
|
|
129
|
+
name(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
130
|
+
path(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
131
|
+
query(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
132
|
+
headers(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
133
|
+
cookies(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
134
|
+
};
|
|
135
|
+
response: {
|
|
136
|
+
status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
137
|
+
headers(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
138
|
+
body(node: ast.OperationNode): string;
|
|
139
|
+
/**
|
|
140
|
+
* Name of the per-status record of an operation's responses. Generated only with `inferred: true`.
|
|
141
|
+
*/
|
|
142
|
+
responses(node: ast.OperationNode): string;
|
|
143
|
+
response(node: ast.OperationNode): string;
|
|
144
|
+
error(node: ast.OperationNode): string;
|
|
145
|
+
/**
|
|
146
|
+
* Inferred type name of an operation's combined `{ body, path, query, headers }` object.
|
|
147
|
+
* Generated only with `inferred: true`.
|
|
148
|
+
*/
|
|
149
|
+
options(node: ast.OperationNode): string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
type Options = OutputOptions & {
|
|
153
|
+
/**
|
|
154
|
+
* Skip any operation, tag, path, or schema that matches one of these patterns.
|
|
155
|
+
*/
|
|
156
|
+
exclude?: Array<Exclude>;
|
|
157
|
+
/**
|
|
158
|
+
* Generate only the operations, tags, paths, or schemas that match one of these patterns.
|
|
159
|
+
*/
|
|
160
|
+
include?: Array<Include>;
|
|
161
|
+
/**
|
|
162
|
+
* Apply different plugin options to the operations or schemas that match a pattern.
|
|
163
|
+
*/
|
|
164
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
165
|
+
/**
|
|
166
|
+
* Module specifier the generated files import `v` from.
|
|
167
|
+
*
|
|
168
|
+
* @default 'valibot'
|
|
169
|
+
*/
|
|
170
|
+
importPath?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Export a type alias next to every schema: `v.InferInput` for a request schema, which is the
|
|
173
|
+
* value the caller passes, and `v.InferOutput` for every other schema.
|
|
174
|
+
*/
|
|
175
|
+
inferred?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Convert input before validation with `v.toString()`, `v.toNumber()`, and `v.toDate()`.
|
|
178
|
+
* Pass an object to turn it on per type.
|
|
179
|
+
*
|
|
180
|
+
* @default false
|
|
181
|
+
*/
|
|
182
|
+
coercion?: boolean | {
|
|
183
|
+
dates?: boolean;
|
|
184
|
+
strings?: boolean;
|
|
185
|
+
numbers?: boolean;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Generate an `is*` type guard and an `assert*` function for every component schema.
|
|
189
|
+
*
|
|
190
|
+
* @default false
|
|
191
|
+
*/
|
|
192
|
+
typeGuards?: boolean | {
|
|
193
|
+
is?: boolean;
|
|
194
|
+
assert?: boolean;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Output form for an OpenAPI `pattern` inside `v.regex(...)`: a regex literal (`'literal'`) or
|
|
198
|
+
* the `RegExp` constructor (`'constructor'`).
|
|
199
|
+
*
|
|
200
|
+
* @default 'literal'
|
|
201
|
+
*/
|
|
202
|
+
regexType?: 'literal' | 'constructor';
|
|
203
|
+
/**
|
|
204
|
+
* How a `oneOf` is validated, unless it prints as `v.variant(...)`.
|
|
205
|
+
* - `'union'`: `v.union([...])` with strict object members, which also rejects extra keys the spec allows.
|
|
206
|
+
* - `'xor'`: `v.union([...])` behind a check that passes only when exactly one member matches.
|
|
207
|
+
*
|
|
208
|
+
* @default 'union'
|
|
209
|
+
*/
|
|
210
|
+
oneOfType?: 'union' | 'xor';
|
|
211
|
+
/**
|
|
212
|
+
* Override the names the plugin gives to schemas, types, and files.
|
|
213
|
+
*/
|
|
214
|
+
resolver?: ResolverPatch<ResolverValibot>;
|
|
215
|
+
/**
|
|
216
|
+
* Replace the printed output of a schema node type.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* pluginValibot({
|
|
221
|
+
* printer: {
|
|
222
|
+
* nodes: {
|
|
223
|
+
* date() {
|
|
224
|
+
* return 'v.pipe(v.string(), v.isoDate(), v.transform((value) => new Date(value)))'
|
|
225
|
+
* },
|
|
226
|
+
* },
|
|
227
|
+
* },
|
|
228
|
+
* })
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
printer?: {
|
|
232
|
+
nodes?: PrinterValibotNodes;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* AST macros applied to each schema or operation node before it is printed.
|
|
236
|
+
*/
|
|
237
|
+
macros?: Array<ast.Macro>;
|
|
238
|
+
};
|
|
239
|
+
type ResolvedOptions = {
|
|
240
|
+
output: Output;
|
|
241
|
+
exclude: Array<Exclude>;
|
|
242
|
+
include: Array<Include> | undefined;
|
|
243
|
+
override: Array<Override<ResolvedOptions>>;
|
|
244
|
+
group: Group | null;
|
|
245
|
+
importPath: NonNullable<Options['importPath']>;
|
|
246
|
+
inferred: NonNullable<Options['inferred']>;
|
|
247
|
+
regexType: NonNullable<Options['regexType']>;
|
|
248
|
+
oneOfType: NonNullable<Options['oneOfType']>;
|
|
249
|
+
coercion: NonNullable<Options['coercion']>;
|
|
250
|
+
typeGuards: NonNullable<Options['typeGuards']>;
|
|
251
|
+
printer: Options['printer'];
|
|
252
|
+
};
|
|
253
|
+
type PluginValibot = PluginType<'plugin-valibot', Options, ResolvedOptions, ResolverValibot>;
|
|
254
|
+
declare global {
|
|
255
|
+
namespace Kubb {
|
|
256
|
+
interface PluginRegistry {
|
|
257
|
+
'plugin-valibot': PluginValibot;
|
|
258
|
+
}
|
|
259
|
+
interface MemoRegistry {
|
|
260
|
+
valibotPrinter: ReturnType<typeof printerValibot>;
|
|
261
|
+
valibotDirectionalNodes: WeakMap<ast.SchemaNode, ast.SchemaNode | null>;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Built-in generator for `@kubb/plugin-valibot`. Emits one Valibot schema per schema in the spec,
|
|
267
|
+
* plus the parameter, request, and response schemas of each operation.
|
|
268
|
+
*/
|
|
269
|
+
export declare const valibotGenerator: import("@kubb/kit").Generator<PluginValibot, unknown>;
|
|
270
|
+
/**
|
|
271
|
+
* Canonical plugin name for `@kubb/plugin-valibot`. Used for driver lookups and cross-plugin
|
|
272
|
+
* dependency references.
|
|
273
|
+
*/
|
|
274
|
+
export declare const pluginValibotName = "plugin-valibot";
|
|
275
|
+
/**
|
|
276
|
+
* Generates Valibot v1 schemas from an OpenAPI spec. Use them to validate API responses at
|
|
277
|
+
* runtime, build form schemas, or pass them to any library that takes a Standard Schema.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import { defineConfig } from 'kubb/config'
|
|
282
|
+
* import { pluginValibot } from '@kubb/plugin-valibot'
|
|
283
|
+
*
|
|
284
|
+
* export default defineConfig({
|
|
285
|
+
* input: './petStore.yaml',
|
|
286
|
+
* output: { path: './src/gen' },
|
|
287
|
+
* plugins: [
|
|
288
|
+
* pluginValibot({
|
|
289
|
+
* output: { path: './valibot' },
|
|
290
|
+
* inferred: true,
|
|
291
|
+
* }),
|
|
292
|
+
* ],
|
|
293
|
+
* })
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export declare const pluginValibot: import("@kubb/kit").PluginFactory<PluginValibot>;
|
|
297
|
+
/**
|
|
298
|
+
* Default resolver for `@kubb/plugin-valibot`. Schema and file names are camelCase with a `Schema`
|
|
299
|
+
* suffix, and inferred types are PascalCase.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* resolverValibot.name('list pets') // 'listPetsSchema'
|
|
304
|
+
* resolverValibot.schema.typeName('pet') // 'PetSchemaType'
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export declare const resolverValibot: ResolverValibot;
|
|
308
|
+
export { type PluginValibot, type PrinterValibotFactory, type PrinterValibotNodes, type PrinterValibotOptions, type ResolverValibot, pluginValibot as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
+
/**
|
|
3
|
+
* Partial map of node-type overrides for the Valibot printer, keyed by `SchemaType`. Each function
|
|
4
|
+
* replaces the built-in handler and can call `this.transform`, `this.base`, and `this.options`.
|
|
5
|
+
*/
|
|
6
|
+
type PrinterValibotNodes = ast.PrinterPartial<string, PrinterValibotOptions>;
|
|
7
|
+
type PrinterValibotOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Output form for an OpenAPI `pattern` inside `v.regex(...)`.
|
|
10
|
+
*
|
|
11
|
+
* @default 'literal'
|
|
12
|
+
*/
|
|
13
|
+
regexType?: PluginValibot['resolvedOptions']['regexType'];
|
|
14
|
+
/**
|
|
15
|
+
* How a `oneOf` without a discriminator is validated: strict members, or exactly one match.
|
|
16
|
+
*
|
|
17
|
+
* @default 'union'
|
|
18
|
+
*/
|
|
19
|
+
oneOfType?: PluginValibot['resolvedOptions']['oneOfType'];
|
|
20
|
+
/**
|
|
21
|
+
* Convert input before validation: `v.toString()`, `v.toNumber()`, and `v.toDate()`.
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
coercion?: PluginValibot['resolvedOptions']['coercion'];
|
|
26
|
+
/**
|
|
27
|
+
* Which way a node converts between its wire type and its runtime type:
|
|
28
|
+
* - `'decode'` (default): wire into runtime, used by response schemas.
|
|
29
|
+
* - `'encode'`: runtime back to wire, used by request bodies and parameters.
|
|
30
|
+
*
|
|
31
|
+
* A handler that returns different output per direction makes the generator emit an
|
|
32
|
+
* `${name}InputSchema` variant for that component.
|
|
33
|
+
*/
|
|
34
|
+
direction?: 'encode' | 'decode';
|
|
35
|
+
/**
|
|
36
|
+
* The adapter's `dateType`. `'stringLocal'` drops the timestamp check, because Valibot has no
|
|
37
|
+
* check for a date-time without an offset.
|
|
38
|
+
*/
|
|
39
|
+
dateType?: ast.ParserOptions['dateType'];
|
|
40
|
+
/**
|
|
41
|
+
* Turns a schema name from the spec into the name of its generated const.
|
|
42
|
+
*/
|
|
43
|
+
resolver?: ResolverValibot;
|
|
44
|
+
/**
|
|
45
|
+
* Property names to drop from the printed object with `v.omit(...)`.
|
|
46
|
+
*/
|
|
47
|
+
keysToOmit?: Array<string> | null;
|
|
48
|
+
/**
|
|
49
|
+
* Schema names that are part of a circular reference. A `$ref` to one of them prints inside
|
|
50
|
+
* `v.lazy(() => ...)`.
|
|
51
|
+
*/
|
|
52
|
+
cyclicSchemas?: ReadonlySet<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Custom handler map for node type overrides.
|
|
55
|
+
*/
|
|
56
|
+
nodes?: PrinterValibotNodes;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Factory options for the Valibot printer: its name, options, and output types.
|
|
60
|
+
*/
|
|
61
|
+
type PrinterValibotFactory = ast.PrinterFactoryOptions<'valibot', PrinterValibotOptions, string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Valibot v1 printer. Turns a `SchemaNode` into the code of a Valibot schema.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const printer = printerValibot({})
|
|
68
|
+
*
|
|
69
|
+
* printer.print(ast.factory.createSchema({ type: 'string', min: 1 })) // 'v.pipe(v.string(), v.minLength(1))'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const printerValibot: (options?: PrinterValibotOptions | undefined) => ast.Printer<PrinterValibotFactory>;
|
|
73
|
+
/**
|
|
74
|
+
* The names the plugin gives to generated schemas and their inferred types.
|
|
75
|
+
*/
|
|
76
|
+
type ResolverValibot = Resolver & {
|
|
77
|
+
schema: {
|
|
78
|
+
/**
|
|
79
|
+
* The inferred type name of a component schema.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* resolver.schema.typeName('pet') // 'PetSchemaType'
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
typeName(name: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* The inferred type name of an operation schema, which already ends in `Schema`.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* resolver.schema.type('addPetBodySchema') // 'AddPetBodySchemaType'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
type(name: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* The name of the request variant of a component schema, which encodes where the schema decodes.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* resolver.schema.inputName('pet') // 'petInputSchema'
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
inputName(name: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* The inferred type name of the request variant.
|
|
107
|
+
*/
|
|
108
|
+
inputTypeName(name: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* The name of the type guard of a component schema.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* resolver.schema.isName('pet') // 'isPet'
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
isName(name: string): string;
|
|
118
|
+
/**
|
|
119
|
+
* The name of the assertion function of a component schema.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* resolver.schema.assertName('pet') // 'assertPet'
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
assertName(name: string): string;
|
|
127
|
+
};
|
|
128
|
+
param: {
|
|
129
|
+
name(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
130
|
+
path(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
131
|
+
query(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
132
|
+
headers(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
133
|
+
cookies(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
134
|
+
};
|
|
135
|
+
response: {
|
|
136
|
+
status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
137
|
+
headers(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
138
|
+
body(node: ast.OperationNode): string;
|
|
139
|
+
/**
|
|
140
|
+
* Name of the per-status record of an operation's responses. Generated only with `inferred: true`.
|
|
141
|
+
*/
|
|
142
|
+
responses(node: ast.OperationNode): string;
|
|
143
|
+
response(node: ast.OperationNode): string;
|
|
144
|
+
error(node: ast.OperationNode): string;
|
|
145
|
+
/**
|
|
146
|
+
* Inferred type name of an operation's combined `{ body, path, query, headers }` object.
|
|
147
|
+
* Generated only with `inferred: true`.
|
|
148
|
+
*/
|
|
149
|
+
options(node: ast.OperationNode): string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
type Options = OutputOptions & {
|
|
153
|
+
/**
|
|
154
|
+
* Skip any operation, tag, path, or schema that matches one of these patterns.
|
|
155
|
+
*/
|
|
156
|
+
exclude?: Array<Exclude>;
|
|
157
|
+
/**
|
|
158
|
+
* Generate only the operations, tags, paths, or schemas that match one of these patterns.
|
|
159
|
+
*/
|
|
160
|
+
include?: Array<Include>;
|
|
161
|
+
/**
|
|
162
|
+
* Apply different plugin options to the operations or schemas that match a pattern.
|
|
163
|
+
*/
|
|
164
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
165
|
+
/**
|
|
166
|
+
* Module specifier the generated files import `v` from.
|
|
167
|
+
*
|
|
168
|
+
* @default 'valibot'
|
|
169
|
+
*/
|
|
170
|
+
importPath?: string;
|
|
171
|
+
/**
|
|
172
|
+
* Export a type alias next to every schema: `v.InferInput` for a request schema, which is the
|
|
173
|
+
* value the caller passes, and `v.InferOutput` for every other schema.
|
|
174
|
+
*/
|
|
175
|
+
inferred?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Convert input before validation with `v.toString()`, `v.toNumber()`, and `v.toDate()`.
|
|
178
|
+
* Pass an object to turn it on per type.
|
|
179
|
+
*
|
|
180
|
+
* @default false
|
|
181
|
+
*/
|
|
182
|
+
coercion?: boolean | {
|
|
183
|
+
dates?: boolean;
|
|
184
|
+
strings?: boolean;
|
|
185
|
+
numbers?: boolean;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Generate an `is*` type guard and an `assert*` function for every component schema.
|
|
189
|
+
*
|
|
190
|
+
* @default false
|
|
191
|
+
*/
|
|
192
|
+
typeGuards?: boolean | {
|
|
193
|
+
is?: boolean;
|
|
194
|
+
assert?: boolean;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Output form for an OpenAPI `pattern` inside `v.regex(...)`: a regex literal (`'literal'`) or
|
|
198
|
+
* the `RegExp` constructor (`'constructor'`).
|
|
199
|
+
*
|
|
200
|
+
* @default 'literal'
|
|
201
|
+
*/
|
|
202
|
+
regexType?: 'literal' | 'constructor';
|
|
203
|
+
/**
|
|
204
|
+
* How a `oneOf` is validated, unless it prints as `v.variant(...)`.
|
|
205
|
+
* - `'union'`: `v.union([...])` with strict object members, which also rejects extra keys the spec allows.
|
|
206
|
+
* - `'xor'`: `v.union([...])` behind a check that passes only when exactly one member matches.
|
|
207
|
+
*
|
|
208
|
+
* @default 'union'
|
|
209
|
+
*/
|
|
210
|
+
oneOfType?: 'union' | 'xor';
|
|
211
|
+
/**
|
|
212
|
+
* Override the names the plugin gives to schemas, types, and files.
|
|
213
|
+
*/
|
|
214
|
+
resolver?: ResolverPatch<ResolverValibot>;
|
|
215
|
+
/**
|
|
216
|
+
* Replace the printed output of a schema node type.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* pluginValibot({
|
|
221
|
+
* printer: {
|
|
222
|
+
* nodes: {
|
|
223
|
+
* date() {
|
|
224
|
+
* return 'v.pipe(v.string(), v.isoDate(), v.transform((value) => new Date(value)))'
|
|
225
|
+
* },
|
|
226
|
+
* },
|
|
227
|
+
* },
|
|
228
|
+
* })
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
printer?: {
|
|
232
|
+
nodes?: PrinterValibotNodes;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* AST macros applied to each schema or operation node before it is printed.
|
|
236
|
+
*/
|
|
237
|
+
macros?: Array<ast.Macro>;
|
|
238
|
+
};
|
|
239
|
+
type ResolvedOptions = {
|
|
240
|
+
output: Output;
|
|
241
|
+
exclude: Array<Exclude>;
|
|
242
|
+
include: Array<Include> | undefined;
|
|
243
|
+
override: Array<Override<ResolvedOptions>>;
|
|
244
|
+
group: Group | null;
|
|
245
|
+
importPath: NonNullable<Options['importPath']>;
|
|
246
|
+
inferred: NonNullable<Options['inferred']>;
|
|
247
|
+
regexType: NonNullable<Options['regexType']>;
|
|
248
|
+
oneOfType: NonNullable<Options['oneOfType']>;
|
|
249
|
+
coercion: NonNullable<Options['coercion']>;
|
|
250
|
+
typeGuards: NonNullable<Options['typeGuards']>;
|
|
251
|
+
printer: Options['printer'];
|
|
252
|
+
};
|
|
253
|
+
type PluginValibot = PluginType<'plugin-valibot', Options, ResolvedOptions, ResolverValibot>;
|
|
254
|
+
declare global {
|
|
255
|
+
namespace Kubb {
|
|
256
|
+
interface PluginRegistry {
|
|
257
|
+
'plugin-valibot': PluginValibot;
|
|
258
|
+
}
|
|
259
|
+
interface MemoRegistry {
|
|
260
|
+
valibotPrinter: ReturnType<typeof printerValibot>;
|
|
261
|
+
valibotDirectionalNodes: WeakMap<ast.SchemaNode, ast.SchemaNode | null>;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Built-in generator for `@kubb/plugin-valibot`. Emits one Valibot schema per schema in the spec,
|
|
267
|
+
* plus the parameter, request, and response schemas of each operation.
|
|
268
|
+
*/
|
|
269
|
+
export declare const valibotGenerator: import("@kubb/kit").Generator<PluginValibot, unknown>;
|
|
270
|
+
/**
|
|
271
|
+
* Canonical plugin name for `@kubb/plugin-valibot`. Used for driver lookups and cross-plugin
|
|
272
|
+
* dependency references.
|
|
273
|
+
*/
|
|
274
|
+
export declare const pluginValibotName = "plugin-valibot";
|
|
275
|
+
/**
|
|
276
|
+
* Generates Valibot v1 schemas from an OpenAPI spec. Use them to validate API responses at
|
|
277
|
+
* runtime, build form schemas, or pass them to any library that takes a Standard Schema.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import { defineConfig } from 'kubb/config'
|
|
282
|
+
* import { pluginValibot } from '@kubb/plugin-valibot'
|
|
283
|
+
*
|
|
284
|
+
* export default defineConfig({
|
|
285
|
+
* input: './petStore.yaml',
|
|
286
|
+
* output: { path: './src/gen' },
|
|
287
|
+
* plugins: [
|
|
288
|
+
* pluginValibot({
|
|
289
|
+
* output: { path: './valibot' },
|
|
290
|
+
* inferred: true,
|
|
291
|
+
* }),
|
|
292
|
+
* ],
|
|
293
|
+
* })
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export declare const pluginValibot: import("@kubb/kit").PluginFactory<PluginValibot>;
|
|
297
|
+
/**
|
|
298
|
+
* Default resolver for `@kubb/plugin-valibot`. Schema and file names are camelCase with a `Schema`
|
|
299
|
+
* suffix, and inferred types are PascalCase.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* resolverValibot.name('list pets') // 'listPetsSchema'
|
|
304
|
+
* resolverValibot.schema.typeName('pet') // 'PetSchemaType'
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export declare const resolverValibot: ResolverValibot;
|
|
308
|
+
export { type PluginValibot, type PrinterValibotFactory, type PrinterValibotNodes, type PrinterValibotOptions, type ResolverValibot, pluginValibot as default };
|