import { URLPath } from '@kubb/core/utils' import { useOperations } from '@kubb/plugin-oas/hooks' import { Const, File, Parser, useApp } from '@kubb/react' import type { HttpMethod, Operation } from '@kubb/oas' import type { KubbNode } from '@kubb/react' import type { ComponentProps, ComponentType } from 'react' import type { FileMeta, PluginClient } from '../types.ts' type TemplateProps = { /** * Name of the function */ name: string operations: Operation[] baseURL: string | undefined } function Template({ name, operations }: TemplateProps): KubbNode { const operationsObject: Record = {} operations.forEach((operation) => { operationsObject[operation.getOperationId()] = { path: new URLPath(operation.path).URL, method: operation.method, } }) return ( {JSON.stringify(operationsObject, undefined, 2)} ) } type RootTemplateProps = { children?: React.ReactNode } function RootTemplate({ children }: RootTemplateProps) { const { pluginManager, plugin: { key: pluginKey }, } = useApp() const file = pluginManager.getFile({ name: 'operations', extName: '.ts', pluginKey }) return ( baseName={file.baseName} path={file.path} meta={file.meta} exportable={false}> {children} ) } const defaultTemplates = { default: Template, root: RootTemplate } as const type Templates = Partial type Props = { baseURL: string | undefined /** * This will make it possible to override the default behaviour. */ Template?: ComponentType> } export function Operations({ baseURL, Template = defaultTemplates.default }: Props): KubbNode { const operations = useOperations() return