@kubb/plugin-zod 3.0.0-alpha.1 → 3.0.0-alpha.3
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/dist/{chunk-64Z35OF4.cjs → chunk-7X3NWYUN.cjs} +105 -154
- package/dist/chunk-7X3NWYUN.cjs.map +1 -0
- package/dist/{chunk-V6DUT3EA.js → chunk-XCGVHLYD.js} +168 -217
- package/dist/chunk-XCGVHLYD.js.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/src/SchemaGenerator.tsx +19 -28
- package/src/components/OperationSchema.tsx +1 -3
- package/src/components/Schema.tsx +1 -10
- package/src/plugin.ts +7 -16
- package/dist/chunk-64Z35OF4.cjs.map +0 -1
- package/dist/chunk-V6DUT3EA.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -54
|
@@ -1,5 +1,71 @@
|
|
|
1
|
+
// src/components/Operations.tsx
|
|
2
|
+
import { useOperationManager, useOperations } from "@kubb/plugin-oas/hooks";
|
|
3
|
+
import { Const, File, Parser, useApp } from "@kubb/react";
|
|
4
|
+
import transformers from "@kubb/core/transformers";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
6
|
+
function Template({ operationsName, pathsName, operations }) {
|
|
7
|
+
const { groupSchemasByName } = useOperationManager();
|
|
8
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
9
|
+
const operationsJSON = transformedOperations.reduce(
|
|
10
|
+
(prev, acc) => {
|
|
11
|
+
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
12
|
+
return prev;
|
|
13
|
+
},
|
|
14
|
+
{}
|
|
15
|
+
);
|
|
16
|
+
const pathsJSON = transformedOperations.reduce(
|
|
17
|
+
(prev, acc) => {
|
|
18
|
+
prev[`"${acc.operation.path}"`] = {
|
|
19
|
+
...prev[`"${acc.operation.path}"`] || {},
|
|
20
|
+
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
21
|
+
};
|
|
22
|
+
return prev;
|
|
23
|
+
},
|
|
24
|
+
{}
|
|
25
|
+
);
|
|
26
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
|
+
/* @__PURE__ */ jsx(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers.stringifyObject(operationsJSON)}}` }),
|
|
28
|
+
/* @__PURE__ */ jsx(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers.stringifyObject(pathsJSON)}}` })
|
|
29
|
+
] });
|
|
30
|
+
}
|
|
31
|
+
function RootTemplate({ children }) {
|
|
32
|
+
const {
|
|
33
|
+
mode,
|
|
34
|
+
pluginManager,
|
|
35
|
+
plugin: {
|
|
36
|
+
key: pluginKey,
|
|
37
|
+
options: { extName }
|
|
38
|
+
}
|
|
39
|
+
} = useApp();
|
|
40
|
+
const { getFile } = useOperationManager();
|
|
41
|
+
const operations = useOperations();
|
|
42
|
+
const { groupSchemasByName } = useOperationManager();
|
|
43
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
44
|
+
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
45
|
+
const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
|
|
46
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
47
|
+
return /* @__PURE__ */ jsx(File.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
|
|
48
|
+
}).filter(Boolean);
|
|
49
|
+
return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
|
|
50
|
+
mode === "split" && imports,
|
|
51
|
+
/* @__PURE__ */ jsx(File.Source, { children })
|
|
52
|
+
] }) });
|
|
53
|
+
}
|
|
54
|
+
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
55
|
+
function Operations({ Template: Template3 = defaultTemplates.default }) {
|
|
56
|
+
const operations = useOperations();
|
|
57
|
+
return /* @__PURE__ */ jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
58
|
+
}
|
|
59
|
+
Operations.File = function(props) {
|
|
60
|
+
const templates = { ...defaultTemplates, ...props.templates };
|
|
61
|
+
const Template3 = templates.default;
|
|
62
|
+
const RootTemplate2 = templates.root;
|
|
63
|
+
return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
|
|
64
|
+
};
|
|
65
|
+
Operations.templates = defaultTemplates;
|
|
66
|
+
|
|
1
67
|
// src/components/Schema.tsx
|
|
2
|
-
import { Oas as
|
|
68
|
+
import { Oas as Oas6 } from "@kubb/plugin-oas/components";
|
|
3
69
|
import { Const as Const2, File as File6, Type as Type2, useApp as useApp6, useFile } from "@kubb/react";
|
|
4
70
|
|
|
5
71
|
// ../plugin-ts/src/plugin.ts
|
|
@@ -15,42 +81,42 @@ import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
|
15
81
|
import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
16
82
|
|
|
17
83
|
// ../plugin-ts/src/components/OasType.tsx
|
|
18
|
-
import { Parser, File, Type, useApp } from "@kubb/react";
|
|
84
|
+
import { Parser as Parser2, File as File2, Type, useApp as useApp2 } from "@kubb/react";
|
|
19
85
|
import { useOas } from "@kubb/plugin-oas/hooks";
|
|
20
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
21
|
-
function
|
|
22
|
-
return /* @__PURE__ */
|
|
86
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
87
|
+
function Template2({ name, typeName, api }) {
|
|
88
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
23
89
|
`export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
|
|
24
|
-
/* @__PURE__ */
|
|
25
|
-
/* @__PURE__ */
|
|
90
|
+
/* @__PURE__ */ jsx2("br", {}),
|
|
91
|
+
/* @__PURE__ */ jsx2(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
|
|
26
92
|
] });
|
|
27
93
|
}
|
|
28
|
-
var
|
|
29
|
-
function OasType({ name, typeName, Template: Template3 =
|
|
94
|
+
var defaultTemplates2 = { default: Template2 };
|
|
95
|
+
function OasType({ name, typeName, Template: Template3 = defaultTemplates2.default }) {
|
|
30
96
|
const oas = useOas();
|
|
31
|
-
return /* @__PURE__ */
|
|
97
|
+
return /* @__PURE__ */ jsx2(Template3, { name, typeName, api: oas.api });
|
|
32
98
|
}
|
|
33
|
-
OasType.File = function({ name, typeName, templates =
|
|
99
|
+
OasType.File = function({ name, typeName, templates = defaultTemplates2 }) {
|
|
34
100
|
const {
|
|
35
101
|
pluginManager,
|
|
36
102
|
plugin: { key: pluginKey }
|
|
37
|
-
} =
|
|
103
|
+
} = useApp2();
|
|
38
104
|
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
39
105
|
const Template3 = templates.default;
|
|
40
|
-
return /* @__PURE__ */
|
|
41
|
-
/* @__PURE__ */
|
|
42
|
-
/* @__PURE__ */
|
|
106
|
+
return /* @__PURE__ */ jsx2(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
107
|
+
/* @__PURE__ */ jsx2(File2.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
108
|
+
/* @__PURE__ */ jsx2(File2.Source, { children: /* @__PURE__ */ jsx2(OasType, { Template: Template3, name, typeName }) })
|
|
43
109
|
] }) });
|
|
44
110
|
};
|
|
45
|
-
OasType.templates =
|
|
111
|
+
OasType.templates = defaultTemplates2;
|
|
46
112
|
|
|
47
113
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
48
|
-
import
|
|
114
|
+
import transformers4 from "@kubb/core/transformers";
|
|
49
115
|
import { print as print2 } from "@kubb/parser-ts";
|
|
50
116
|
import * as factory3 from "@kubb/parser-ts/factory";
|
|
51
117
|
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
52
|
-
import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
53
|
-
import { File as
|
|
118
|
+
import { useOas as useOas2, useOperation, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
|
|
119
|
+
import { File as File4, Parser as Parser3, useApp as useApp4 } from "@kubb/react";
|
|
54
120
|
|
|
55
121
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
56
122
|
import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
|
|
@@ -59,15 +125,15 @@ import { App, createRoot } from "@kubb/react";
|
|
|
59
125
|
|
|
60
126
|
// ../plugin-ts/src/components/Schema.tsx
|
|
61
127
|
import { Oas } from "@kubb/plugin-oas/components";
|
|
62
|
-
import { File as
|
|
63
|
-
import
|
|
128
|
+
import { File as File3, useApp as useApp3 } from "@kubb/react";
|
|
129
|
+
import transformers3 from "@kubb/core/transformers";
|
|
64
130
|
import { print } from "@kubb/parser-ts";
|
|
65
131
|
import * as factory2 from "@kubb/parser-ts/factory";
|
|
66
132
|
import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
67
133
|
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
68
134
|
|
|
69
135
|
// ../plugin-ts/src/parser/index.ts
|
|
70
|
-
import
|
|
136
|
+
import transformers2 from "@kubb/core/transformers";
|
|
71
137
|
import * as factory from "@kubb/parser-ts/factory";
|
|
72
138
|
import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
73
139
|
var typeKeywordMapper = {
|
|
@@ -236,7 +302,7 @@ function parse(parent, current, options) {
|
|
|
236
302
|
return factory.appendJSDocToNode({
|
|
237
303
|
node: propertySignature,
|
|
238
304
|
comments: [
|
|
239
|
-
describeSchema ? `@description ${
|
|
305
|
+
describeSchema ? `@description ${transformers2.jsStringEscape(describeSchema.args)}` : void 0,
|
|
240
306
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
241
307
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
242
308
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
@@ -265,7 +331,7 @@ function parse(parent, current, options) {
|
|
|
265
331
|
}
|
|
266
332
|
|
|
267
333
|
// ../plugin-ts/src/components/Schema.tsx
|
|
268
|
-
import { jsx as
|
|
334
|
+
import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
|
|
269
335
|
function Schema(props) {
|
|
270
336
|
const { keysToOmit, description } = props;
|
|
271
337
|
const { tree, name } = useSchema();
|
|
@@ -274,7 +340,7 @@ function Schema(props) {
|
|
|
274
340
|
plugin: {
|
|
275
341
|
options: { mapper, enumType, optionalType }
|
|
276
342
|
}
|
|
277
|
-
} =
|
|
343
|
+
} = useApp3();
|
|
278
344
|
const resolvedName = pluginManager.resolveName({
|
|
279
345
|
name,
|
|
280
346
|
pluginKey: [pluginTsName],
|
|
@@ -323,9 +389,9 @@ function Schema(props) {
|
|
|
323
389
|
enumSchemas.forEach((enumSchema) => {
|
|
324
390
|
extraNodes.push(
|
|
325
391
|
...factory2.createEnumDeclaration({
|
|
326
|
-
name:
|
|
392
|
+
name: transformers3.camelCase(enumSchema.args.name),
|
|
327
393
|
typeName: enumSchema.args.typeName,
|
|
328
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
394
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers3.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
329
395
|
type: enumType
|
|
330
396
|
})
|
|
331
397
|
);
|
|
@@ -334,7 +400,7 @@ function Schema(props) {
|
|
|
334
400
|
nodes.push(
|
|
335
401
|
factory2.appendJSDocToNode({
|
|
336
402
|
node,
|
|
337
|
-
comments: [description ? `@description ${
|
|
403
|
+
comments: [description ? `@description ${transformers3.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
338
404
|
})
|
|
339
405
|
);
|
|
340
406
|
const filterdNodes = nodes.filter(
|
|
@@ -345,13 +411,13 @@ function Schema(props) {
|
|
|
345
411
|
return print([...extraNodes, ...filterdNodes]);
|
|
346
412
|
}
|
|
347
413
|
Schema.File = function({}) {
|
|
348
|
-
const { pluginManager } =
|
|
414
|
+
const { pluginManager } = useApp3();
|
|
349
415
|
const { schema } = useSchema();
|
|
350
|
-
return /* @__PURE__ */
|
|
416
|
+
return /* @__PURE__ */ jsx3(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx3(File3.Source, { children: /* @__PURE__ */ jsx3(Schema, { description: schema?.description }) }) });
|
|
351
417
|
};
|
|
352
418
|
|
|
353
419
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
354
|
-
import { jsx as
|
|
420
|
+
import { jsx as jsx4 } from "@kubb/react/jsx-runtime";
|
|
355
421
|
var SchemaGenerator2 = class extends Generator {
|
|
356
422
|
async schema(name, schema, options) {
|
|
357
423
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
@@ -360,14 +426,14 @@ var SchemaGenerator2 = class extends Generator {
|
|
|
360
426
|
});
|
|
361
427
|
const tree = this.parse({ schema, name });
|
|
362
428
|
root.render(
|
|
363
|
-
/* @__PURE__ */
|
|
429
|
+
/* @__PURE__ */ jsx4(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx4(Oas2, { oas, children: /* @__PURE__ */ jsx4(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx4(Schema.File, {}) }) }) })
|
|
364
430
|
);
|
|
365
431
|
return root.files;
|
|
366
432
|
}
|
|
367
433
|
};
|
|
368
434
|
|
|
369
435
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
370
|
-
import { jsx as
|
|
436
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
|
|
371
437
|
function printCombinedSchema({
|
|
372
438
|
name,
|
|
373
439
|
operation,
|
|
@@ -436,7 +502,7 @@ function printCombinedSchema({
|
|
|
436
502
|
return void 0;
|
|
437
503
|
}
|
|
438
504
|
return factory3.createPropertySignature({
|
|
439
|
-
name:
|
|
505
|
+
name: transformers4.pascalCase(key),
|
|
440
506
|
type
|
|
441
507
|
});
|
|
442
508
|
}).filter(Boolean)
|
|
@@ -446,12 +512,12 @@ function printCombinedSchema({
|
|
|
446
512
|
return print2(namespaceNode);
|
|
447
513
|
}
|
|
448
514
|
function OperationSchema({ keysToOmit, description }) {
|
|
449
|
-
return /* @__PURE__ */
|
|
515
|
+
return /* @__PURE__ */ jsx5(Schema, { keysToOmit, description });
|
|
450
516
|
}
|
|
451
517
|
OperationSchema.File = function({}) {
|
|
452
|
-
const { pluginManager, plugin, mode, fileManager } =
|
|
518
|
+
const { pluginManager, plugin, mode, fileManager } = useApp4();
|
|
453
519
|
const oas = useOas2();
|
|
454
|
-
const { getSchemas, getFile, getName } =
|
|
520
|
+
const { getSchemas, getFile, getName } = useOperationManager2();
|
|
455
521
|
const operation = useOperation();
|
|
456
522
|
const file = getFile(operation);
|
|
457
523
|
const schemas = getSchemas(operation);
|
|
@@ -466,19 +532,19 @@ OperationSchema.File = function({}) {
|
|
|
466
532
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
467
533
|
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
468
534
|
const tree = generator.parse({ schema, name });
|
|
469
|
-
return /* @__PURE__ */
|
|
470
|
-
mode === "split" && /* @__PURE__ */
|
|
471
|
-
/* @__PURE__ */
|
|
535
|
+
return /* @__PURE__ */ jsxs3(Oas3.Schema, { name, value: schema, tree, children: [
|
|
536
|
+
mode === "split" && /* @__PURE__ */ jsx5(Oas3.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
|
|
537
|
+
/* @__PURE__ */ jsx5(File4.Source, { children: /* @__PURE__ */ jsx5(OperationSchema, { description, keysToOmit }) })
|
|
472
538
|
] }, i);
|
|
473
539
|
};
|
|
474
|
-
return /* @__PURE__ */
|
|
540
|
+
return /* @__PURE__ */ jsx5(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs3(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
475
541
|
items.map(mapItem),
|
|
476
|
-
/* @__PURE__ */
|
|
542
|
+
/* @__PURE__ */ jsx5(File4.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
|
|
477
543
|
] }) });
|
|
478
544
|
};
|
|
479
545
|
|
|
480
546
|
// ../plugin-ts/src/OperationGenerator.tsx
|
|
481
|
-
import { jsx as
|
|
547
|
+
import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
|
|
482
548
|
var OperationGenerator = class extends Generator2 {
|
|
483
549
|
async all(operations) {
|
|
484
550
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
@@ -486,7 +552,7 @@ var OperationGenerator = class extends Generator2 {
|
|
|
486
552
|
logger: pluginManager.logger
|
|
487
553
|
});
|
|
488
554
|
root.render(
|
|
489
|
-
/* @__PURE__ */
|
|
555
|
+
/* @__PURE__ */ jsx6(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx6(OasType.File, { name: "oas", typeName: "Oas" }) }) })
|
|
490
556
|
);
|
|
491
557
|
return root.files;
|
|
492
558
|
}
|
|
@@ -496,7 +562,7 @@ var OperationGenerator = class extends Generator2 {
|
|
|
496
562
|
logger: pluginManager.logger
|
|
497
563
|
});
|
|
498
564
|
root.render(
|
|
499
|
-
/* @__PURE__ */
|
|
565
|
+
/* @__PURE__ */ jsx6(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx6(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx6(OperationSchema.File, {}) }) }) })
|
|
500
566
|
);
|
|
501
567
|
return root.files;
|
|
502
568
|
}
|
|
@@ -557,22 +623,16 @@ var pluginTs = createPlugin((options) => {
|
|
|
557
623
|
}
|
|
558
624
|
return resolvedName;
|
|
559
625
|
},
|
|
560
|
-
async writeFile(path3, source) {
|
|
561
|
-
if (!path3.endsWith(".ts") || !source) {
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
return this.fileManager.write(path3, source, { sanity: false });
|
|
565
|
-
},
|
|
566
626
|
async buildStart() {
|
|
567
627
|
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
568
|
-
const oas = await swaggerPlugin.
|
|
628
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
569
629
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
570
630
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
571
631
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
572
632
|
oas,
|
|
573
633
|
pluginManager: this.pluginManager,
|
|
574
634
|
plugin: this.plugin,
|
|
575
|
-
contentType: swaggerPlugin.
|
|
635
|
+
contentType: swaggerPlugin.context.contentType,
|
|
576
636
|
include: void 0,
|
|
577
637
|
override,
|
|
578
638
|
mode,
|
|
@@ -584,7 +644,7 @@ var pluginTs = createPlugin((options) => {
|
|
|
584
644
|
oas,
|
|
585
645
|
pluginManager: this.pluginManager,
|
|
586
646
|
plugin: this.plugin,
|
|
587
|
-
contentType: swaggerPlugin.
|
|
647
|
+
contentType: swaggerPlugin.context.contentType,
|
|
588
648
|
exclude,
|
|
589
649
|
include,
|
|
590
650
|
override,
|
|
@@ -614,7 +674,7 @@ import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kub
|
|
|
614
674
|
import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
|
|
615
675
|
|
|
616
676
|
// src/parser/index.ts
|
|
617
|
-
import
|
|
677
|
+
import transformers5 from "@kubb/core/transformers";
|
|
618
678
|
import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
|
|
619
679
|
var zodKeywordMapper = {
|
|
620
680
|
any: () => "z.any()",
|
|
@@ -734,7 +794,7 @@ function sort(items) {
|
|
|
734
794
|
if (!items) {
|
|
735
795
|
return [];
|
|
736
796
|
}
|
|
737
|
-
return
|
|
797
|
+
return transformers5.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
738
798
|
}
|
|
739
799
|
function parse2(parent, current, options) {
|
|
740
800
|
const value = zodKeywordMapper[current.keyword];
|
|
@@ -783,9 +843,9 @@ function parse2(parent, current, options) {
|
|
|
783
843
|
return zodKeywordMapper.enum(
|
|
784
844
|
current.args.items.map((schema) => {
|
|
785
845
|
if (schema.format === "number") {
|
|
786
|
-
return
|
|
846
|
+
return transformers5.stringify(schema.value);
|
|
787
847
|
}
|
|
788
|
-
return
|
|
848
|
+
return transformers5.stringify(schema.value);
|
|
789
849
|
})
|
|
790
850
|
);
|
|
791
851
|
}
|
|
@@ -823,11 +883,11 @@ function parse2(parent, current, options) {
|
|
|
823
883
|
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
824
884
|
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
825
885
|
}
|
|
826
|
-
return zodKeywordMapper.const(
|
|
886
|
+
return zodKeywordMapper.const(transformers5.stringify(current.args.value));
|
|
827
887
|
}
|
|
828
888
|
if (isKeyword2(current, schemaKeywords3.matches)) {
|
|
829
889
|
if (current.args) {
|
|
830
|
-
return zodKeywordMapper.matches(
|
|
890
|
+
return zodKeywordMapper.matches(transformers5.toRegExpString(current.args));
|
|
831
891
|
}
|
|
832
892
|
}
|
|
833
893
|
if (isKeyword2(current, schemaKeywords3.default)) {
|
|
@@ -837,7 +897,7 @@ function parse2(parent, current, options) {
|
|
|
837
897
|
}
|
|
838
898
|
if (isKeyword2(current, schemaKeywords3.describe)) {
|
|
839
899
|
if (current.args) {
|
|
840
|
-
return zodKeywordMapper.describe(
|
|
900
|
+
return zodKeywordMapper.describe(transformers5.stringify(current.args.toString()));
|
|
841
901
|
}
|
|
842
902
|
}
|
|
843
903
|
if (isKeyword2(current, schemaKeywords3.string)) {
|
|
@@ -876,47 +936,24 @@ import path2 from "path";
|
|
|
876
936
|
import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
|
|
877
937
|
import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
|
|
878
938
|
import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
|
|
879
|
-
import { pluginOasName as pluginOasName2 } from "@kubb/plugin-oas";
|
|
939
|
+
import { OperationGenerator as OperationGenerator2, pluginOasName as pluginOasName2, SchemaGenerator as SchemaGenerator4 } from "@kubb/plugin-oas";
|
|
880
940
|
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
881
941
|
|
|
882
|
-
// src/OperationGenerator.tsx
|
|
883
|
-
import { OperationGenerator as Generator4 } from "@kubb/plugin-oas";
|
|
884
|
-
import { Oas as Oas7 } from "@kubb/plugin-oas/components";
|
|
885
|
-
import { App as App4, createRoot as createRoot4 } from "@kubb/react";
|
|
886
|
-
|
|
887
|
-
// src/components/OperationSchema.tsx
|
|
888
|
-
import { schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
889
|
-
import { Oas as Oas6 } from "@kubb/plugin-oas/components";
|
|
890
|
-
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
|
|
891
|
-
import { File as File4, Parser as Parser3, useApp as useApp4 } from "@kubb/react";
|
|
892
|
-
|
|
893
942
|
// src/SchemaGenerator.tsx
|
|
894
|
-
import {
|
|
895
|
-
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
896
|
-
import { App as App3, createRoot as createRoot3 } from "@kubb/react";
|
|
897
|
-
import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
|
|
898
|
-
var SchemaGenerator3 = class extends Generator3 {
|
|
899
|
-
async schema(name, schema, options) {
|
|
900
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
901
|
-
const root = createRoot3({
|
|
902
|
-
logger: pluginManager.logger
|
|
903
|
-
});
|
|
904
|
-
const tree = this.parse({ schema, name });
|
|
905
|
-
root.render(
|
|
906
|
-
/* @__PURE__ */ jsx6(App3, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx6(Oas5, { oas, children: /* @__PURE__ */ jsx6(Oas5.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx6(Schema2.File, {}) }) }) })
|
|
907
|
-
);
|
|
908
|
-
return root.files;
|
|
909
|
-
}
|
|
910
|
-
};
|
|
943
|
+
import { createReactParser } from "@kubb/plugin-oas";
|
|
911
944
|
|
|
912
945
|
// src/components/OperationSchema.tsx
|
|
913
|
-
import {
|
|
946
|
+
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
947
|
+
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
948
|
+
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
|
|
949
|
+
import { File as File5, Parser as Parser4, useApp as useApp5 } from "@kubb/react";
|
|
950
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
|
|
914
951
|
function OperationSchema2({ description, keysToOmit }) {
|
|
915
952
|
return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
916
953
|
}
|
|
917
954
|
OperationSchema2.File = function({}) {
|
|
918
|
-
const { pluginManager, plugin, mode } =
|
|
919
|
-
const { getSchemas, getFile } =
|
|
955
|
+
const { pluginManager, plugin, mode } = useApp5();
|
|
956
|
+
const { getSchemas, getFile } = useOperationManager3();
|
|
920
957
|
const oas = useOas3();
|
|
921
958
|
const operation = useOperation2();
|
|
922
959
|
const file = getFile(operation);
|
|
@@ -933,111 +970,34 @@ OperationSchema2.File = function({}) {
|
|
|
933
970
|
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
934
971
|
const optional = !required && !!name.includes("Params");
|
|
935
972
|
const tree = generator.parse({ schema, name });
|
|
936
|
-
return /* @__PURE__ */
|
|
937
|
-
mode === "split" && /* @__PURE__ */ jsx7(
|
|
938
|
-
/* @__PURE__ */ jsx7(
|
|
973
|
+
return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
|
|
974
|
+
mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { extName: plugin.options.extName }),
|
|
975
|
+
/* @__PURE__ */ jsx7(File5.Source, { children: /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit }) })
|
|
939
976
|
] }, i);
|
|
940
977
|
};
|
|
941
|
-
return /* @__PURE__ */ jsx7(
|
|
942
|
-
/* @__PURE__ */ jsx7(
|
|
978
|
+
return /* @__PURE__ */ jsx7(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
979
|
+
/* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
943
980
|
items.map(mapItem)
|
|
944
981
|
] }) });
|
|
945
982
|
};
|
|
946
983
|
|
|
947
|
-
// src/
|
|
948
|
-
import {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
955
|
-
const operationsJSON = transformedOperations.reduce(
|
|
956
|
-
(prev, acc) => {
|
|
957
|
-
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
958
|
-
return prev;
|
|
959
|
-
},
|
|
960
|
-
{}
|
|
961
|
-
);
|
|
962
|
-
const pathsJSON = transformedOperations.reduce(
|
|
963
|
-
(prev, acc) => {
|
|
964
|
-
prev[`"${acc.operation.path}"`] = {
|
|
965
|
-
...prev[`"${acc.operation.path}"`] || {},
|
|
966
|
-
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
967
|
-
};
|
|
968
|
-
return prev;
|
|
969
|
-
},
|
|
970
|
-
{}
|
|
971
|
-
);
|
|
972
|
-
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
973
|
-
/* @__PURE__ */ jsx8(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }),
|
|
974
|
-
/* @__PURE__ */ jsx8(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` })
|
|
975
|
-
] });
|
|
976
|
-
}
|
|
977
|
-
function RootTemplate({ children }) {
|
|
978
|
-
const {
|
|
979
|
-
mode,
|
|
980
|
-
pluginManager,
|
|
981
|
-
plugin: {
|
|
982
|
-
key: pluginKey,
|
|
983
|
-
options: { extName }
|
|
984
|
+
// src/SchemaGenerator.tsx
|
|
985
|
+
import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
|
|
986
|
+
var zodParser = createReactParser({
|
|
987
|
+
name: "plugin-zod",
|
|
988
|
+
Operations({ options }) {
|
|
989
|
+
if (!options.templates.operations) {
|
|
990
|
+
return null;
|
|
984
991
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
993
|
-
return /* @__PURE__ */ jsx8(File5.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
|
|
994
|
-
}).filter(Boolean);
|
|
995
|
-
return /* @__PURE__ */ jsx8(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
|
|
996
|
-
mode === "split" && imports,
|
|
997
|
-
/* @__PURE__ */ jsx8(File5.Source, { children })
|
|
998
|
-
] }) });
|
|
999
|
-
}
|
|
1000
|
-
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
1001
|
-
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
1002
|
-
const operations = useOperations();
|
|
1003
|
-
return /* @__PURE__ */ jsx8(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
1004
|
-
}
|
|
1005
|
-
Operations.File = function(props) {
|
|
1006
|
-
const templates = { ...defaultTemplates2, ...props.templates };
|
|
1007
|
-
const Template3 = templates.default;
|
|
1008
|
-
const RootTemplate2 = templates.root;
|
|
1009
|
-
return /* @__PURE__ */ jsx8(RootTemplate2, { children: /* @__PURE__ */ jsx8(Operations, { Template: Template3 }) });
|
|
1010
|
-
};
|
|
1011
|
-
Operations.templates = defaultTemplates2;
|
|
1012
|
-
|
|
1013
|
-
// src/OperationGenerator.tsx
|
|
1014
|
-
import { jsx as jsx9 } from "@kubb/react/jsx-runtime";
|
|
1015
|
-
var OperationGenerator2 = class extends Generator4 {
|
|
1016
|
-
async all(operations, _operationsByMethod) {
|
|
1017
|
-
const { pluginManager, oas, plugin, mode } = this.context;
|
|
1018
|
-
const root = createRoot4({
|
|
1019
|
-
logger: pluginManager.logger
|
|
1020
|
-
});
|
|
1021
|
-
const templates = {
|
|
1022
|
-
operations: Operations.templates,
|
|
1023
|
-
...this.options.templates
|
|
1024
|
-
};
|
|
1025
|
-
root.render(
|
|
1026
|
-
/* @__PURE__ */ jsx9(App4, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx9(Oas7, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ jsx9(Operations.File, { templates: templates.operations }) }) })
|
|
1027
|
-
);
|
|
1028
|
-
return root.files;
|
|
1029
|
-
}
|
|
1030
|
-
async operation(operation, options) {
|
|
1031
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
1032
|
-
const root = createRoot4({
|
|
1033
|
-
logger: pluginManager.logger
|
|
1034
|
-
});
|
|
1035
|
-
root.render(
|
|
1036
|
-
/* @__PURE__ */ jsx9(App4, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx9(Oas7, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx9(Oas7.Operation, { operation, children: /* @__PURE__ */ jsx9(OperationSchema2.File, {}) }) }) })
|
|
1037
|
-
);
|
|
1038
|
-
return root.files;
|
|
992
|
+
return /* @__PURE__ */ jsx8(Operations.File, { templates: options.templates.operations });
|
|
993
|
+
},
|
|
994
|
+
Operation() {
|
|
995
|
+
return /* @__PURE__ */ jsx8(OperationSchema2.File, {});
|
|
996
|
+
},
|
|
997
|
+
Schema({ schema, name }) {
|
|
998
|
+
return /* @__PURE__ */ jsx8(Schema2.File, {});
|
|
1039
999
|
}
|
|
1040
|
-
};
|
|
1000
|
+
});
|
|
1041
1001
|
|
|
1042
1002
|
// src/plugin.ts
|
|
1043
1003
|
var pluginZodName = "plugin-zod";
|
|
@@ -1105,40 +1065,34 @@ var pluginZod = createPlugin2((options) => {
|
|
|
1105
1065
|
}
|
|
1106
1066
|
return resolvedName;
|
|
1107
1067
|
},
|
|
1108
|
-
async writeFile(path3, source) {
|
|
1109
|
-
if (!path3.endsWith(".ts") || !source) {
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
return this.fileManager.write(path3, source, { sanity: false });
|
|
1113
|
-
},
|
|
1114
1068
|
async buildStart() {
|
|
1115
1069
|
const [swaggerPlugin] = PluginManager2.getDependedPlugins(this.plugins, [pluginOasName2]);
|
|
1116
|
-
const oas = await swaggerPlugin.
|
|
1070
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
1117
1071
|
const root = path2.resolve(this.config.root, this.config.output.path);
|
|
1118
1072
|
const mode = FileManager2.getMode(path2.resolve(root, output.path));
|
|
1119
|
-
const schemaGenerator = new
|
|
1073
|
+
const schemaGenerator = new SchemaGenerator4(this.plugin.options, {
|
|
1120
1074
|
oas,
|
|
1121
1075
|
pluginManager: this.pluginManager,
|
|
1122
1076
|
plugin: this.plugin,
|
|
1123
|
-
contentType: swaggerPlugin.
|
|
1077
|
+
contentType: swaggerPlugin.context.contentType,
|
|
1124
1078
|
include: void 0,
|
|
1125
1079
|
override,
|
|
1126
1080
|
mode,
|
|
1127
1081
|
output: output.path
|
|
1128
1082
|
});
|
|
1129
|
-
const schemaFiles = await schemaGenerator.build();
|
|
1083
|
+
const schemaFiles = await schemaGenerator.build(zodParser);
|
|
1130
1084
|
await this.addFile(...schemaFiles);
|
|
1131
1085
|
const operationGenerator = new OperationGenerator2(this.plugin.options, {
|
|
1132
1086
|
oas,
|
|
1133
1087
|
pluginManager: this.pluginManager,
|
|
1134
1088
|
plugin: this.plugin,
|
|
1135
|
-
contentType: swaggerPlugin.
|
|
1089
|
+
contentType: swaggerPlugin.context.contentType,
|
|
1136
1090
|
exclude,
|
|
1137
1091
|
include,
|
|
1138
1092
|
override,
|
|
1139
1093
|
mode
|
|
1140
1094
|
});
|
|
1141
|
-
const operationFiles = await operationGenerator.build();
|
|
1095
|
+
const operationFiles = await operationGenerator.build(zodParser);
|
|
1142
1096
|
await this.addFile(...operationFiles);
|
|
1143
1097
|
},
|
|
1144
1098
|
async buildEnd() {
|
|
@@ -1169,7 +1123,7 @@ var pluginZod = createPlugin2((options) => {
|
|
|
1169
1123
|
});
|
|
1170
1124
|
|
|
1171
1125
|
// src/components/Schema.tsx
|
|
1172
|
-
import { Fragment as Fragment3, jsx as
|
|
1126
|
+
import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
|
|
1173
1127
|
function Schema2(props) {
|
|
1174
1128
|
const { keysToOmit, withTypeAnnotation, description } = props;
|
|
1175
1129
|
const { tree, name } = useSchema2();
|
|
@@ -1195,7 +1149,7 @@ function Schema2(props) {
|
|
|
1195
1149
|
type: "type"
|
|
1196
1150
|
});
|
|
1197
1151
|
if (!tree.length) {
|
|
1198
|
-
return /* @__PURE__ */
|
|
1152
|
+
return /* @__PURE__ */ jsx9(
|
|
1199
1153
|
Const2,
|
|
1200
1154
|
{
|
|
1201
1155
|
name: resolvedName,
|
|
@@ -1216,7 +1170,7 @@ function Schema2(props) {
|
|
|
1216
1170
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
1217
1171
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
1218
1172
|
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1219
|
-
/* @__PURE__ */
|
|
1173
|
+
/* @__PURE__ */ jsx9(
|
|
1220
1174
|
Const2,
|
|
1221
1175
|
{
|
|
1222
1176
|
export: true,
|
|
@@ -1231,7 +1185,7 @@ function Schema2(props) {
|
|
|
1231
1185
|
].filter(Boolean).join("") || ""
|
|
1232
1186
|
}
|
|
1233
1187
|
),
|
|
1234
|
-
typedSchema && /* @__PURE__ */
|
|
1188
|
+
typedSchema && /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
|
|
1235
1189
|
] });
|
|
1236
1190
|
}
|
|
1237
1191
|
Schema2.File = function({}) {
|
|
@@ -1241,14 +1195,11 @@ Schema2.File = function({}) {
|
|
|
1241
1195
|
options: { typed }
|
|
1242
1196
|
}
|
|
1243
1197
|
} = useApp6();
|
|
1244
|
-
const {
|
|
1245
|
-
const withData = tree.some(
|
|
1246
|
-
(schema2) => schema2.keyword === schemaKeywords5.array || schema2.keyword === schemaKeywords5.and || schema2.keyword === schemaKeywords5.object || schema2.keyword === schemaKeywords5.union || schema2.keyword === schemaKeywords5.tuple
|
|
1247
|
-
);
|
|
1198
|
+
const { schema } = useSchema2();
|
|
1248
1199
|
const withTypeAnnotation = !!typed;
|
|
1249
|
-
return /* @__PURE__ */ jsxs5(
|
|
1250
|
-
/* @__PURE__ */
|
|
1251
|
-
/* @__PURE__ */
|
|
1200
|
+
return /* @__PURE__ */ jsxs5(Oas6.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
1201
|
+
/* @__PURE__ */ jsx9(Schema2.Imports, {}),
|
|
1202
|
+
/* @__PURE__ */ jsx9(File6.Source, { children: /* @__PURE__ */ jsx9(Schema2, { withTypeAnnotation, description: schema?.description }) })
|
|
1252
1203
|
] });
|
|
1253
1204
|
};
|
|
1254
1205
|
Schema2.Imports = () => {
|
|
@@ -1276,16 +1227,16 @@ Schema2.Imports = () => {
|
|
|
1276
1227
|
});
|
|
1277
1228
|
const withTypeAnnotation = !!typed;
|
|
1278
1229
|
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1279
|
-
/* @__PURE__ */
|
|
1280
|
-
withTypeAnnotation && typeName && typePath && /* @__PURE__ */
|
|
1230
|
+
/* @__PURE__ */ jsx9(File6.Import, { name: ["z"], path: importPath }),
|
|
1231
|
+
withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx9(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
1281
1232
|
] });
|
|
1282
1233
|
};
|
|
1283
1234
|
|
|
1284
1235
|
export {
|
|
1236
|
+
Operations,
|
|
1285
1237
|
Schema2 as Schema,
|
|
1286
1238
|
OperationSchema2 as OperationSchema,
|
|
1287
|
-
Operations,
|
|
1288
1239
|
pluginZodName,
|
|
1289
1240
|
pluginZod
|
|
1290
1241
|
};
|
|
1291
|
-
//# sourceMappingURL=chunk-
|
|
1242
|
+
//# sourceMappingURL=chunk-XCGVHLYD.js.map
|