import path from 'node:path' import { usePluginManager } from '@kubb/core/hooks' import { createReactGenerator } from '@kubb/plugin-oas/generators' import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks' import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { pluginZodName } from '@kubb/plugin-zod' import { File } from '@kubb/react-fabric' import { Client } from '../components/Client' import { Url } from '../components/Url.tsx' import type { PluginClient } from '../types' export const clientGenerator = createReactGenerator({ name: 'client', Operation({ config, plugin, operation, generator }) { const pluginManager = usePluginManager() const { options, options: { output, urlType }, } = plugin const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager(generator) const client = { name: getName(operation, { type: 'function' }), file: getFile(operation), } const url = { name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }), file: getFile(operation), } const type = { file: getFile(operation, { pluginKey: [pluginTsName] }), schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }), } const zod = { file: getFile(operation, { pluginKey: [pluginZodName] }), schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }), } const isFormData = operation.getContentType() === 'multipart/form-data' return ( {options.importPath ? ( <> ) : ( <> )} {isFormData && type.schemas.request?.name && ( )} {options.parser === 'zod' && ( Boolean(x))} root={client.file.path} path={zod.file.path} /> )} item.name) || []), ].filter((x): x is string => Boolean(x))} root={client.file.path} path={type.file.path} isTypeOnly /> ) }, })