@kubb/plugin-zod 3.10.11 → 3.10.12
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-IHJH3HEP.cjs → chunk-JVTFLOY2.cjs} +4 -3
- package/dist/chunk-JVTFLOY2.cjs.map +1 -0
- package/dist/{chunk-7WGESVYS.js → chunk-SMUC347B.js} +4 -3
- package/dist/chunk-SMUC347B.js.map +1 -0
- package/dist/generators.cjs +3 -3
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/package.json +11 -11
- package/src/generators/__snapshots__/getPets.ts +4 -6
- package/src/generators/__snapshots__/getPets_wrapOutput.ts +4 -6
- package/src/generators/__snapshots__/queryAllDefaulted.ts +19 -0
- package/src/generators/__snapshots__/queryAllDefaulted_wrapOutput.ts +19 -0
- package/src/generators/zodGenerator.tsx +3 -1
- package/dist/chunk-7WGESVYS.js.map +0 -1
- package/dist/chunk-IHJH3HEP.cjs.map +0 -1
|
@@ -29,7 +29,8 @@ var zodGenerator = pluginOas.createReactGenerator({
|
|
|
29
29
|
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
30
30
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options2 }, i) => {
|
|
31
31
|
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
32
|
-
const
|
|
32
|
+
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => property.hasOwnProperty("default") && property.default !== void 0);
|
|
33
|
+
const optional = !required && !someDefaults && name.includes("Params");
|
|
33
34
|
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
34
35
|
const imports = schemaManager.getImports(tree);
|
|
35
36
|
const group = options2.operation ? getGroup(options2.operation) : void 0;
|
|
@@ -175,5 +176,5 @@ var operationsGenerator = pluginOas.createReactGenerator({
|
|
|
175
176
|
|
|
176
177
|
exports.operationsGenerator = operationsGenerator;
|
|
177
178
|
exports.zodGenerator = zodGenerator;
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
179
|
-
//# sourceMappingURL=chunk-
|
|
179
|
+
//# sourceMappingURL=chunk-JVTFLOY2.cjs.map
|
|
180
|
+
//# sourceMappingURL=chunk-JVTFLOY2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","getBanner","getFooter","Operations"],"mappings":";;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAaC,yBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAA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kE,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAEjB,IAAA,uBACEG,eAAAA;AAAA,MAACH,UAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQI,gBAAU,EAAE,GAAA,EAAK,QAAQ,MAAQ,EAAA,aAAA,CAAc,QAAQ,CAAA;AAAA,QAC/D,MAAQC,EAAAA,eAAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEhC,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,cAAAA,CAACK,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA;AAAA;AAAA,KAC7D;AAAA;AAGN,CAAC","file":"chunk-JVTFLOY2.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => property.hasOwnProperty('default') && property.default !== undefined);\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -27,7 +27,8 @@ var zodGenerator = createReactGenerator({
|
|
|
27
27
|
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
28
28
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options2 }, i) => {
|
|
29
29
|
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
30
|
-
const
|
|
30
|
+
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => property.hasOwnProperty("default") && property.default !== void 0);
|
|
31
|
+
const optional = !required && !someDefaults && name.includes("Params");
|
|
31
32
|
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
32
33
|
const imports = schemaManager.getImports(tree);
|
|
33
34
|
const group = options2.operation ? getGroup(options2.operation) : void 0;
|
|
@@ -172,5 +173,5 @@ var operationsGenerator = createReactGenerator({
|
|
|
172
173
|
});
|
|
173
174
|
|
|
174
175
|
export { operationsGenerator, zodGenerator };
|
|
175
|
-
//# sourceMappingURL=chunk-
|
|
176
|
-
//# sourceMappingURL=chunk-
|
|
176
|
+
//# sourceMappingURL=chunk-SMUC347B.js.map
|
|
177
|
+
//# sourceMappingURL=chunk-SMUC347B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["options","createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAa,mBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgB,gBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAI,eAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WAAa,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAQ,EAC5I,IAAK,EAAA,CACL,OAAO,OAAO,CAAA;AAEjB,IAAM,MAAA,kBAAA,GAAqB,CAAC,EAAE,IAAM,EAAA,MAAA,EAAQ,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,MAAQC,EAAAA,SAAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEhC,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,GAAAA,CAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA;AAAA;AAAA,KAC7D;AAAA;AAGN,CAAC","file":"chunk-SMUC347B.js","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => property.hasOwnProperty('default') && property.default !== undefined);\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkJVTFLOY2_cjs = require('./chunk-JVTFLOY2.cjs');
|
|
4
4
|
require('./chunk-OQOBL3NO.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "operationsGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkJVTFLOY2_cjs.operationsGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "zodGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkJVTFLOY2_cjs.zodGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkJVTFLOY2_cjs = require('./chunk-JVTFLOY2.cjs');
|
|
4
4
|
require('./chunk-OQOBL3NO.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
@@ -29,7 +29,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
29
29
|
importPath = "zod",
|
|
30
30
|
coercion = false,
|
|
31
31
|
inferred = false,
|
|
32
|
-
generators = [
|
|
32
|
+
generators = [chunkJVTFLOY2_cjs.zodGenerator, operations ? chunkJVTFLOY2_cjs.operationsGenerator : void 0].filter(Boolean),
|
|
33
33
|
wrapOutput = void 0,
|
|
34
34
|
contentType
|
|
35
35
|
} = options;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { zodGenerator, operationsGenerator } from './chunk-
|
|
1
|
+
import { zodGenerator, operationsGenerator } from './chunk-SMUC347B.js';
|
|
2
2
|
import './chunk-HR3ED4EJ.js';
|
|
3
|
-
import path from '
|
|
3
|
+
import path from 'path';
|
|
4
4
|
import { createPlugin, PluginManager, FileManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
6
|
import { pluginOasName, SchemaGenerator, OperationGenerator } from '@kubb/plugin-oas';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.12",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -66,21 +66,21 @@
|
|
|
66
66
|
"!/**/__tests__/**"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "3.10.
|
|
70
|
-
"@kubb/oas": "3.10.
|
|
71
|
-
"@kubb/parser-ts": "3.10.
|
|
72
|
-
"@kubb/plugin-
|
|
73
|
-
"@kubb/
|
|
74
|
-
"@kubb/
|
|
69
|
+
"@kubb/core": "3.10.12",
|
|
70
|
+
"@kubb/oas": "3.10.12",
|
|
71
|
+
"@kubb/parser-ts": "3.10.12",
|
|
72
|
+
"@kubb/plugin-ts": "3.10.12",
|
|
73
|
+
"@kubb/react": "3.10.12",
|
|
74
|
+
"@kubb/plugin-oas": "3.10.12"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@asteasolutions/zod-to-openapi": "^7.3.0",
|
|
78
78
|
"@hono/zod-openapi": "0.19.2",
|
|
79
|
-
"tsup": "^8.
|
|
79
|
+
"tsup": "^8.5.0",
|
|
80
80
|
"zod": "~3.24.4",
|
|
81
|
-
"@kubb/config-ts": "3.10.
|
|
82
|
-
"@kubb/config-tsup": "3.10.
|
|
83
|
-
"@kubb/plugin-oas": "3.10.
|
|
81
|
+
"@kubb/config-ts": "3.10.12",
|
|
82
|
+
"@kubb/config-tsup": "3.10.12",
|
|
83
|
+
"@kubb/plugin-oas": "3.10.12"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@kubb/react": "^3.0.0"
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod'
|
|
6
6
|
|
|
7
|
-
export const listPetsQueryParams = z
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
.optional()
|
|
7
|
+
export const listPetsQueryParams = z.object({
|
|
8
|
+
limit: z.string().describe('How many items to return at one time (max 100)').optional(),
|
|
9
|
+
offset: z.coerce.number().int().default(0),
|
|
10
|
+
})
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* @description A paged array of pets
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from '@hono/zod-openapi'
|
|
6
6
|
|
|
7
|
-
export const listPetsQueryParams = z
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
.optional()
|
|
7
|
+
export const listPetsQueryParams = z.object({
|
|
8
|
+
limit: z.string().describe('How many items to return at one time (max 100)').optional(),
|
|
9
|
+
offset: z.coerce.number().int().default(0),
|
|
10
|
+
})
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* @description A paged array of pets
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
7
|
+
export const getThingsQueryParams = z.object({
|
|
8
|
+
limit: z.coerce.number().int().min(1).max(100).default(100).describe('Maximum number of things to return'),
|
|
9
|
+
skip: z.coerce.number().int().min(0).default(0).describe('Number of things to skip'),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description A list of things
|
|
14
|
+
*/
|
|
15
|
+
export const getThings200 = z.object({
|
|
16
|
+
items: z.array(z.lazy(() => thing)),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const getThingsQueryResponse = z.lazy(() => getThings200)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@hono/zod-openapi'
|
|
6
|
+
|
|
7
|
+
export const getThingsQueryParams = z.object({
|
|
8
|
+
limit: z.coerce.number().int().min(1).max(100).default(100).describe('Maximum number of things to return'),
|
|
9
|
+
skip: z.coerce.number().int().min(0).default(0).describe('Number of things to skip'),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description A list of things
|
|
14
|
+
*/
|
|
15
|
+
export const getThings200 = z.object({
|
|
16
|
+
items: z.array(z.lazy(() => thing)),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const getThingsQueryResponse = z.lazy(() => getThings200)
|
|
@@ -34,7 +34,9 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
34
34
|
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {
|
|
35
35
|
// hack so Params can be optional when needed
|
|
36
36
|
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required
|
|
37
|
-
const
|
|
37
|
+
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => property.hasOwnProperty('default') && property.default !== undefined);
|
|
38
|
+
const optional = !required && !someDefaults && name.includes('Params')
|
|
39
|
+
|
|
38
40
|
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)
|
|
39
41
|
const imports = schemaManager.getImports(tree)
|
|
40
42
|
const group = options.operation ? getGroup(options.operation) : undefined
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["options","createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAa,mBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgB,gBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAI,eAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WAAa,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAQ,EAC5I,IAAK,EAAA,CACL,OAAO,OAAO,CA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AAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA;AAAA;AAAA,KAC7D;AAAA;AAGN,CAAC","file":"chunk-7WGESVYS.js","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const optional = !required && name.includes('Params')\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","getBanner","getFooter","Operations"],"mappings":";;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAaC,yBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WAAa,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAQ,EAC5I,IAAK,EAAA,CACL,OAAO,OAAO,CAAA;AAEjB,IAAM,MAAA,kBAAA,GAAqB,CAAC,EAAE,IAAM,EAAA,MAAA,EAAQ,YAAc,EAAA,WAAA,EAAa,UAAY,EAAA,GAAGC,QAAQ,EAAA,EAAwB,CAA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":"chunk-IHJH3HEP.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const optional = !required && name.includes('Params')\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|