@kubb/plugin-zod 3.0.0-alpha.0 → 3.0.0-alpha.10
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/{Operations-BlQtRP31.d.cts → Operations-BG26e_MW.d.cts} +1 -1
- package/dist/{Operations-BlQtRP31.d.ts → Operations-BG26e_MW.d.ts} +1 -1
- package/dist/chunk-57AHBVYK.cjs +3502 -0
- package/dist/chunk-57AHBVYK.cjs.map +1 -0
- package/dist/chunk-CUPQVLRZ.js +3502 -0
- package/dist/chunk-CUPQVLRZ.js.map +1 -0
- package/dist/components.cjs +6 -2
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/components.js +6 -2
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +4 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -17
- package/dist/index.d.ts +3 -17
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/SchemaGenerator.tsx +19 -28
- package/src/components/OperationSchema.tsx +8 -14
- package/src/components/Operations.tsx +18 -16
- package/src/components/Schema.tsx +35 -40
- package/src/components/__snapshots__/operations.ts +47 -44
- package/src/index.ts +0 -13
- package/src/parser/index.ts +10 -2
- package/src/plugin.ts +20 -39
- package/src/types.ts +0 -6
- package/dist/chunk-7IAXQL4T.cjs +0 -1291
- package/dist/chunk-7IAXQL4T.cjs.map +0 -1
- package/dist/chunk-OXCOZC6T.js +0 -1291
- package/dist/chunk-OXCOZC6T.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -54
package/dist/components.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/components.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,0JAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-zod/dist/components.cjs"}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/components.cjs","../src/components/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACPA,8CAAA,CAAA;ADSA;AACE;AACA;AACA;AACF,0JAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-zod/dist/components.cjs","sourcesContent":[null,"export { OperationSchema } from './OperationSchema.tsx'\nexport { Operations } from './Operations.tsx'\nexport { Schema } from './Schema.tsx'\n"]}
|
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
export { O as Operations } from './Operations-
|
|
2
|
+
export { O as Operations } from './Operations-BG26e_MW.cjs';
|
|
3
3
|
import '@kubb/oas';
|
|
4
|
-
import '@kubb/react';
|
|
4
|
+
import '@kubb/react/types';
|
|
5
5
|
|
|
6
6
|
type Props$1 = {
|
|
7
7
|
description?: string;
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
export { O as Operations } from './Operations-
|
|
2
|
+
export { O as Operations } from './Operations-BG26e_MW.js';
|
|
3
3
|
import '@kubb/oas';
|
|
4
|
-
import '@kubb/react';
|
|
4
|
+
import '@kubb/react/types';
|
|
5
5
|
|
|
6
6
|
type Props$1 = {
|
|
7
7
|
description?: string;
|
package/dist/components.js
CHANGED
package/dist/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/components/index.ts"],"sourcesContent":["export { OperationSchema } from './OperationSchema.tsx'\nexport { Operations } from './Operations.tsx'\nexport { Schema } from './Schema.tsx'\n"],"mappings":";;;;;;;;AAAA;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var _chunk7IAXQL4Tcjs = require('./chunk-7IAXQL4T.cjs');
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
var definePluginDefault = _chunk7IAXQL4Tcjs.pluginZod;
|
|
8
|
-
var definePlugin = _chunk7IAXQL4Tcjs.pluginZod;
|
|
9
|
-
var src_default = definePluginDefault;
|
|
10
4
|
|
|
5
|
+
var _chunk57AHBVYKcjs = require('./chunk-57AHBVYK.cjs');
|
|
11
6
|
|
|
7
|
+
// src/index.ts
|
|
8
|
+
_chunk57AHBVYKcjs.init_cjs_shims.call(void 0, );
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
|
|
15
|
-
exports.
|
|
12
|
+
exports.pluginZod = _chunk57AHBVYKcjs.pluginZod; exports.pluginZodName = _chunk57AHBVYKcjs.pluginZodName;
|
|
16
13
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACNA,8CAAA,CAAA;ADQA;AACE;AACA;AACF,yGAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-zod/dist/index.cjs","sourcesContent":[null,"export { pluginZod, pluginZodName } from './plugin.ts'\nexport type { PluginZod } from './types.ts'\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
4
|
import { SchemaObject } from '@kubb/oas';
|
|
5
5
|
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
6
|
-
import { O as Operations } from './Operations-
|
|
7
|
-
import '@kubb/react';
|
|
6
|
+
import { O as Operations } from './Operations-BG26e_MW.cjs';
|
|
7
|
+
import '@kubb/react/types';
|
|
8
8
|
import 'react';
|
|
9
9
|
|
|
10
10
|
type Templates = {
|
|
@@ -135,22 +135,8 @@ type ResolvedOptions = {
|
|
|
135
135
|
coercion: NonNullable<Options['coercion']>;
|
|
136
136
|
};
|
|
137
137
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
138
|
-
declare module '@kubb/core' {
|
|
139
|
-
interface _Register {
|
|
140
|
-
['@kubb/plugin-zod']: PluginZod;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
138
|
|
|
144
139
|
declare const pluginZodName = "plugin-zod";
|
|
145
140
|
declare const pluginZod: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
149
|
-
*/
|
|
150
|
-
declare const definePluginDefault: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
151
|
-
/**
|
|
152
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
153
|
-
*/
|
|
154
|
-
declare const definePlugin: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
155
|
-
|
|
156
|
-
export { type PluginZod, definePluginDefault as default, definePlugin, pluginZod, pluginZodName };
|
|
142
|
+
export { type PluginZod, pluginZod, pluginZodName };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
4
|
import { SchemaObject } from '@kubb/oas';
|
|
5
5
|
import { ResolvePathOptions, Exclude, Include, Override, Schema } from '@kubb/plugin-oas';
|
|
6
|
-
import { O as Operations } from './Operations-
|
|
7
|
-
import '@kubb/react';
|
|
6
|
+
import { O as Operations } from './Operations-BG26e_MW.js';
|
|
7
|
+
import '@kubb/react/types';
|
|
8
8
|
import 'react';
|
|
9
9
|
|
|
10
10
|
type Templates = {
|
|
@@ -135,22 +135,8 @@ type ResolvedOptions = {
|
|
|
135
135
|
coercion: NonNullable<Options['coercion']>;
|
|
136
136
|
};
|
|
137
137
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
138
|
-
declare module '@kubb/core' {
|
|
139
|
-
interface _Register {
|
|
140
|
-
['@kubb/plugin-zod']: PluginZod;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
138
|
|
|
144
139
|
declare const pluginZodName = "plugin-zod";
|
|
145
140
|
declare const pluginZod: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
149
|
-
*/
|
|
150
|
-
declare const definePluginDefault: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
151
|
-
/**
|
|
152
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
153
|
-
*/
|
|
154
|
-
declare const definePlugin: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginZod>;
|
|
155
|
-
|
|
156
|
-
export { type PluginZod, definePluginDefault as default, definePlugin, pluginZod, pluginZodName };
|
|
142
|
+
export { type PluginZod, pluginZod, pluginZodName };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
init_esm_shims,
|
|
2
3
|
pluginZod,
|
|
3
4
|
pluginZodName
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CUPQVLRZ.js";
|
|
5
6
|
|
|
6
7
|
// src/index.ts
|
|
7
|
-
|
|
8
|
-
var definePlugin = pluginZod;
|
|
9
|
-
var src_default = definePluginDefault;
|
|
8
|
+
init_esm_shims();
|
|
10
9
|
export {
|
|
11
|
-
src_default as default,
|
|
12
|
-
definePlugin,
|
|
13
10
|
pluginZod,
|
|
14
11
|
pluginZodName
|
|
15
12
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { pluginZod, pluginZodName } from './plugin.ts'\nexport type { PluginZod } from './types.ts'\n"],"mappings":";;;;;;;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.10",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -56,25 +56,25 @@
|
|
|
56
56
|
"!/**/__tests__/**"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@kubb/core": "3.0.0-alpha.
|
|
60
|
-
"@kubb/
|
|
61
|
-
"@kubb/
|
|
62
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
63
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
64
|
-
"@kubb/react": "3.0.0-alpha.
|
|
65
|
-
"@kubb/types": "3.0.0-alpha.
|
|
59
|
+
"@kubb/core": "3.0.0-alpha.10",
|
|
60
|
+
"@kubb/fs": "3.0.0-alpha.10",
|
|
61
|
+
"@kubb/oas": "3.0.0-alpha.10",
|
|
62
|
+
"@kubb/parser-ts": "3.0.0-alpha.10",
|
|
63
|
+
"@kubb/plugin-oas": "3.0.0-alpha.10",
|
|
64
|
+
"@kubb/react": "3.0.0-alpha.10",
|
|
65
|
+
"@kubb/types": "3.0.0-alpha.10"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@types/react": "^18.3.
|
|
68
|
+
"@types/react": "^18.3.5",
|
|
69
69
|
"prettier": "^3.3.3",
|
|
70
70
|
"react": "^18.3.1",
|
|
71
71
|
"tsup": "^8.2.4",
|
|
72
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
73
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
74
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
72
|
+
"@kubb/config-biome": "3.0.0-alpha.10",
|
|
73
|
+
"@kubb/config-ts": "3.0.0-alpha.10",
|
|
74
|
+
"@kubb/config-tsup": "3.0.0-alpha.10"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@kubb/react": "3.0.0-alpha.
|
|
77
|
+
"@kubb/react": "3.0.0-alpha.10"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
80
|
"node": ">=20"
|
package/src/SchemaGenerator.tsx
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { Oas } from '@kubb/plugin-oas/components'
|
|
5
|
-
import { App, createRoot } from '@kubb/react'
|
|
1
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
2
|
+
import { OperationSchema } from './components/OperationSchema.tsx'
|
|
3
|
+
import { Operations } from './components/Operations.tsx'
|
|
6
4
|
import { Schema } from './components/Schema.tsx'
|
|
7
|
-
import type {
|
|
5
|
+
import type { PluginZod } from './types.ts'
|
|
8
6
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export const zodParser = createReactGenerator<PluginZod>({
|
|
8
|
+
name: 'plugin-zod',
|
|
9
|
+
Operations({ options }) {
|
|
10
|
+
if (!options.templates.operations) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<Oas.Schema name={name} value={schema} tree={tree}>
|
|
23
|
-
<Schema.File />
|
|
24
|
-
</Oas.Schema>
|
|
25
|
-
</Oas>
|
|
26
|
-
</App>,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
return root.files
|
|
30
|
-
}
|
|
31
|
-
}
|
|
14
|
+
return <Operations.File templates={options.templates.operations} />
|
|
15
|
+
},
|
|
16
|
+
Operation() {
|
|
17
|
+
return <OperationSchema.File />
|
|
18
|
+
},
|
|
19
|
+
Schema({ schema, name }) {
|
|
20
|
+
return <Schema.File />
|
|
21
|
+
},
|
|
22
|
+
})
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { schemaKeywords } from '@kubb/plugin-oas'
|
|
1
|
+
import { SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
2
2
|
import { Oas } from '@kubb/plugin-oas/components'
|
|
3
3
|
import { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { File,
|
|
5
|
-
|
|
6
|
-
import { SchemaGenerator } from '../SchemaGenerator.tsx'
|
|
4
|
+
import { File, useApp } from '@kubb/react'
|
|
7
5
|
|
|
8
6
|
import type { OperationSchema as OperationSchemaType } from '@kubb/plugin-oas'
|
|
9
7
|
import type { ReactNode } from 'react'
|
|
@@ -47,20 +45,16 @@ OperationSchema.File = function ({}: FileProps): ReactNode {
|
|
|
47
45
|
|
|
48
46
|
return (
|
|
49
47
|
<Oas.Schema key={i} name={name} value={schema} tree={[...tree, optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)}>
|
|
50
|
-
{mode === 'split' && <Oas.Schema.Imports
|
|
51
|
-
<
|
|
52
|
-
<OperationSchema description={description} keysToOmit={keysToOmit} />
|
|
53
|
-
</File.Source>
|
|
48
|
+
{mode === 'split' && <Oas.Schema.Imports isTypeOnly={false} />}
|
|
49
|
+
<OperationSchema description={description} keysToOmit={keysToOmit} />
|
|
54
50
|
</Oas.Schema>
|
|
55
51
|
)
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
return (
|
|
59
|
-
<
|
|
60
|
-
<File
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
</File>
|
|
64
|
-
</Parser>
|
|
55
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
56
|
+
<File.Import name={['z']} path={plugin.options.importPath} />
|
|
57
|
+
{items.map(mapItem)}
|
|
58
|
+
</File>
|
|
65
59
|
)
|
|
66
60
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'
|
|
2
|
-
import { Const, File,
|
|
2
|
+
import { Const, File, useApp } from '@kubb/react'
|
|
3
3
|
|
|
4
4
|
import transformers from '@kubb/core/transformers'
|
|
5
5
|
import type { HttpMethod, Operation } from '@kubb/oas'
|
|
6
|
-
import type { KubbNode } from '@kubb/react'
|
|
6
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
7
7
|
import type { ComponentProps, ComponentType } from 'react'
|
|
8
8
|
import type { FileMeta, PluginZod } from '../types.ts'
|
|
9
9
|
|
|
@@ -46,12 +46,16 @@ function Template({ operationsName, pathsName, operations }: TemplateProps): Kub
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<>
|
|
49
|
-
<
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
<File.Source name={operationsName} isExportable isIndexable>
|
|
50
|
+
<Const export name={operationsName} asConst>
|
|
51
|
+
{`{${transformers.stringifyObject(operationsJSON)}}`}
|
|
52
|
+
</Const>
|
|
53
|
+
</File.Source>
|
|
54
|
+
<File.Source name={pathsName} isExportable isIndexable>
|
|
55
|
+
<Const export name={pathsName} asConst>
|
|
56
|
+
{`{${transformers.stringifyObject(pathsJSON)}}`}
|
|
57
|
+
</Const>
|
|
58
|
+
</File.Source>
|
|
55
59
|
</>
|
|
56
60
|
)
|
|
57
61
|
}
|
|
@@ -76,20 +80,18 @@ function RootTemplate({ children }: RootTemplateProps) {
|
|
|
76
80
|
|
|
77
81
|
const file = pluginManager.getFile({ name: 'operations', extName: '.ts', pluginKey })
|
|
78
82
|
const imports = Object.entries(transformedOperations)
|
|
79
|
-
.map(([
|
|
83
|
+
.map(([key, { data, operation }]) => {
|
|
80
84
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)
|
|
81
85
|
|
|
82
|
-
return <File.Import key={
|
|
86
|
+
return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />
|
|
83
87
|
})
|
|
84
88
|
.filter(Boolean)
|
|
85
89
|
|
|
86
90
|
return (
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
</File>
|
|
92
|
-
</Parser>
|
|
91
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
92
|
+
{mode === 'split' && imports}
|
|
93
|
+
{children}
|
|
94
|
+
</File>
|
|
93
95
|
)
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -46,15 +46,17 @@ export function Schema(props: Props): ReactNode {
|
|
|
46
46
|
|
|
47
47
|
if (!tree.length) {
|
|
48
48
|
return (
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
<File.Source name={resolvedName} isExportable isIndexable>
|
|
50
|
+
<Const
|
|
51
|
+
name={resolvedName}
|
|
52
|
+
export
|
|
53
|
+
JSDoc={{
|
|
54
|
+
comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
undefined
|
|
58
|
+
</Const>
|
|
59
|
+
</File.Source>
|
|
58
60
|
)
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -77,25 +79,29 @@ export function Schema(props: Props): ReactNode {
|
|
|
77
79
|
|
|
78
80
|
return (
|
|
79
81
|
<>
|
|
80
|
-
<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
<File.Source name={resolvedName} isExportable isIndexable>
|
|
83
|
+
<Const
|
|
84
|
+
export
|
|
85
|
+
name={resolvedName}
|
|
86
|
+
JSDoc={{
|
|
87
|
+
comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{[
|
|
91
|
+
output,
|
|
92
|
+
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,
|
|
93
|
+
withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : '',
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.join('') || ''}
|
|
97
|
+
</Const>
|
|
98
|
+
</File.Source>
|
|
95
99
|
{typedSchema && (
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
<File.Source name={resolvedTypeName} isExportable isIndexable isTypeOnly>
|
|
101
|
+
<Type export name={resolvedTypeName}>
|
|
102
|
+
{`z.infer<typeof ${resolvedName}>`}
|
|
103
|
+
</Type>
|
|
104
|
+
</File.Source>
|
|
99
105
|
)}
|
|
100
106
|
</>
|
|
101
107
|
)
|
|
@@ -110,25 +116,14 @@ Schema.File = function ({}: FileProps): ReactNode {
|
|
|
110
116
|
options: { typed },
|
|
111
117
|
},
|
|
112
118
|
} = useApp<PluginZod>()
|
|
113
|
-
const {
|
|
114
|
-
|
|
115
|
-
const withData = tree.some(
|
|
116
|
-
(schema) =>
|
|
117
|
-
schema.keyword === schemaKeywords.array ||
|
|
118
|
-
schema.keyword === schemaKeywords.and ||
|
|
119
|
-
schema.keyword === schemaKeywords.object ||
|
|
120
|
-
schema.keyword === schemaKeywords.union ||
|
|
121
|
-
schema.keyword === schemaKeywords.tuple,
|
|
122
|
-
)
|
|
119
|
+
const { schema } = useSchema()
|
|
123
120
|
|
|
124
121
|
const withTypeAnnotation = !!typed
|
|
125
122
|
|
|
126
123
|
return (
|
|
127
124
|
<Oas.Schema.File output={pluginManager.config.output.path}>
|
|
128
125
|
<Schema.Imports />
|
|
129
|
-
<
|
|
130
|
-
<Schema withTypeAnnotation={withTypeAnnotation} description={schema?.description} />
|
|
131
|
-
</File.Source>
|
|
126
|
+
<Schema withTypeAnnotation={withTypeAnnotation} description={schema?.description} />
|
|
132
127
|
</Oas.Schema.File>
|
|
133
128
|
)
|
|
134
129
|
}
|
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
export const operations = {
|
|
2
|
-
|
|
3
|
-
request: undefined,
|
|
1
|
+
export const operations = {"get_pets-pet-id": {
|
|
2
|
+
request: undefined,
|
|
4
3
|
parameters: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
path: undefined,
|
|
5
|
+
query: undefined,
|
|
6
|
+
header: undefined
|
|
7
|
+
},
|
|
9
8
|
responses: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
errors: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
200: getPetsPetIdQueryResponse,
|
|
10
|
+
default: getPetsPetIdQueryResponse
|
|
11
|
+
},
|
|
12
|
+
errors: {
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"listPets": {
|
|
17
|
+
request: undefined,
|
|
17
18
|
parameters: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
path: undefined,
|
|
20
|
+
query: listPetsQueryParams,
|
|
21
|
+
header: undefined
|
|
22
|
+
},
|
|
22
23
|
responses: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
errors: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
200: listPetsQueryResponse,
|
|
25
|
+
default: listPetsQueryResponse
|
|
26
|
+
},
|
|
27
|
+
errors: {
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"createPets": {
|
|
32
|
+
request: createPetsMutationRequest,
|
|
30
33
|
parameters: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
path: undefined,
|
|
35
|
+
query: undefined,
|
|
36
|
+
header: undefined
|
|
37
|
+
},
|
|
35
38
|
responses: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
errors: {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} as const
|
|
39
|
+
201: createPetsMutationResponse,
|
|
40
|
+
default: createPetsMutationResponse
|
|
41
|
+
},
|
|
42
|
+
errors: {
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
}} as const
|
|
46
|
+
|
|
47
|
+
export const paths = {"/pets/{pet_id}": {
|
|
48
|
+
get: operations["get_pets-pet-id"]
|
|
49
|
+
},
|
|
50
|
+
"/pets": {
|
|
51
|
+
get: operations["listPets"],
|
|
52
|
+
post: operations["createPets"]
|
|
53
|
+
}} as const
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import { pluginZod } from './plugin.ts'
|
|
2
|
-
|
|
3
1
|
export { pluginZod, pluginZodName } from './plugin.ts'
|
|
4
2
|
export type { PluginZod } from './types.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
8
|
-
*/
|
|
9
|
-
const definePluginDefault = pluginZod
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use `import { pluginZod } from '@kubb/plugin-zod'` instead
|
|
12
|
-
*/
|
|
13
|
-
export const definePlugin = pluginZod
|
|
14
|
-
|
|
15
|
-
export default definePluginDefault
|
package/src/parser/index.ts
CHANGED
|
@@ -12,7 +12,11 @@ export const zodKeywordMapper = {
|
|
|
12
12
|
.join('')
|
|
13
13
|
},
|
|
14
14
|
integer: (coercion?: boolean, min?: number, max?: number) => {
|
|
15
|
-
return [
|
|
15
|
+
return [
|
|
16
|
+
coercion ? 'z.coerce.number().int()' : 'z.number().int()',
|
|
17
|
+
min !== undefined ? `.min(${min})` : undefined,
|
|
18
|
+
max !== undefined ? `.max(${max})` : undefined,
|
|
19
|
+
]
|
|
16
20
|
.filter(Boolean)
|
|
17
21
|
.join('')
|
|
18
22
|
},
|
|
@@ -308,10 +312,14 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
|
|
|
308
312
|
return zodKeywordMapper.string(options.coercion)
|
|
309
313
|
}
|
|
310
314
|
|
|
311
|
-
if (isKeyword(current, schemaKeywords.number)
|
|
315
|
+
if (isKeyword(current, schemaKeywords.number)) {
|
|
312
316
|
return zodKeywordMapper.number(options.coercion)
|
|
313
317
|
}
|
|
314
318
|
|
|
319
|
+
if (isKeyword(current, schemaKeywords.integer)) {
|
|
320
|
+
return zodKeywordMapper.integer(options.coercion)
|
|
321
|
+
}
|
|
322
|
+
|
|
315
323
|
if (isKeyword(current, schemaKeywords.min)) {
|
|
316
324
|
return zodKeywordMapper.min(current.args)
|
|
317
325
|
}
|