diff --git a/.changeset/nine-onions-brake.md b/.changeset/nine-onions-brake.md new file mode 100644 index 000000000..6308538d5 --- /dev/null +++ b/.changeset/nine-onions-brake.md @@ -0,0 +1,17 @@ +--- +"@kubb/plugin-svelte-query": minor +"@kubb/plugin-react-query": minor +"@kubb/plugin-solid-query": minor +"@kubb/plugin-vue-query": minor +"@kubb/plugin-client": minor +"@kubb/plugin-faker": minor +"@kubb/plugin-redoc": minor +"@kubb/plugin-msw": minor +"@kubb/plugin-oas": minor +"@kubb/plugin-swr": minor +"@kubb/plugin-zod": minor +"@kubb/plugin-ts": minor +"@kubb/core": minor +--- + +support banner with context for Oas diff --git a/docs/changelog.md b/docs/changelog.md index 9795c52a5..6e6db6edd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,19 @@ title: Changelog # Changelog +## 3.5.0 +- [`core`](/plugins/core): support banner with context for Oas +```typescript +pluginTs({ + output: { + path: 'models', + banner(oas) { + return `// version: ${oas.api.info.version}` + }, + }, +}), +``` + ## 3.4.6 - [`core`](/plugins/core): ignore acronyms when doing casing switch to pascal or camelcase diff --git a/docs/plugins/plugin-client/index.md b/docs/plugins/plugin-client/index.md index 296e30b30..40344e2a0 100644 --- a/docs/plugins/plugin-client/index.md +++ b/docs/plugins/plugin-client/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-faker/index.md b/docs/plugins/plugin-faker/index.md index a5b756274..2fbe59e8d 100644 --- a/docs/plugins/plugin-faker/index.md +++ b/docs/plugins/plugin-faker/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-msw/index.md b/docs/plugins/plugin-msw/index.md index 3aba68a5e..1f79c7708 100644 --- a/docs/plugins/plugin-msw/index.md +++ b/docs/plugins/plugin-msw/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### handlers diff --git a/docs/plugins/plugin-oas/index.md b/docs/plugins/plugin-oas/index.md index a2467564f..9a5a87afd 100644 --- a/docs/plugins/plugin-oas/index.md +++ b/docs/plugins/plugin-oas/index.md @@ -63,18 +63,18 @@ Define what needs to be exported, here you can also disable the export of barrel #### output.banner Add a banner text in the beginning of every file. -| | | -|----------:|:--------------------------------------| -| Type: | `string` | -| Required: | `false` | +| | | +|----------:|:---------------------------------| +| Type: | `string \| (oas: Oas) => string` | +| Required: | `false` | #### output.footer Add a footer text at the end of every file. -| | | -|----------:|:--------------------------------------| -| Type: | `string` | -| Required: | `false` | +| | | +|----------:|:--------| +| Type: | `string \| (oas: Oas) => string` | +| Required: | `false` | ### validate diff --git a/docs/plugins/plugin-react-query/index.md b/docs/plugins/plugin-react-query/index.md index 681ed8c57..34344aeaa 100644 --- a/docs/plugins/plugin-react-query/index.md +++ b/docs/plugins/plugin-react-query/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ## Installation @@ -139,7 +139,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -147,7 +147,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-solid-query/index.md b/docs/plugins/plugin-solid-query/index.md index db09bba38..f27a3cc93 100644 --- a/docs/plugins/plugin-solid-query/index.md +++ b/docs/plugins/plugin-solid-query/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-svelte-query/index.md b/docs/plugins/plugin-svelte-query/index.md index aade58ee8..db8b1ac8a 100644 --- a/docs/plugins/plugin-svelte-query/index.md +++ b/docs/plugins/plugin-svelte-query/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-swr/index.md b/docs/plugins/plugin-swr/index.md index 03c4323b5..6fb4fea5d 100644 --- a/docs/plugins/plugin-swr/index.md +++ b/docs/plugins/plugin-swr/index.md @@ -69,7 +69,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -77,7 +77,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-ts/index.md b/docs/plugins/plugin-ts/index.md index 41183b2c0..d73b8a66d 100644 --- a/docs/plugins/plugin-ts/index.md +++ b/docs/plugins/plugin-ts/index.md @@ -67,7 +67,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -75,7 +75,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | diff --git a/docs/plugins/plugin-vue-query/index.md b/docs/plugins/plugin-vue-query/index.md index 6e1eef3b2..72db31d6b 100644 --- a/docs/plugins/plugin-vue-query/index.md +++ b/docs/plugins/plugin-vue-query/index.md @@ -70,7 +70,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -78,7 +78,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/docs/plugins/plugin-zod/index.md b/docs/plugins/plugin-zod/index.md index 9cfb4eac6..43efc6c29 100644 --- a/docs/plugins/plugin-zod/index.md +++ b/docs/plugins/plugin-zod/index.md @@ -67,7 +67,7 @@ Add a banner text in the beginning of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | #### output.footer @@ -75,7 +75,7 @@ Add a footer text at the end of every file. | | | |----------:|:--------------------------------------| -| Type: | `string` | +| Type: | `string \| (oas: Oas) => string` | | Required: | `false` | ### group diff --git a/examples/client/src/generators/clientStaticGenerator.tsx b/examples/client/src/generators/clientStaticGenerator.tsx index e251bd6cb..a138cdc14 100644 --- a/examples/client/src/generators/clientStaticGenerator.tsx +++ b/examples/client/src/generators/clientStaticGenerator.tsx @@ -3,6 +3,8 @@ import type { PluginClient } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' import { useOperationManager } from '@kubb/plugin-oas/hooks' +import { useOas } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { File, useApp } from '@kubb/react' @@ -14,6 +16,7 @@ export const clientStaticGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const client = { @@ -27,7 +30,13 @@ export const clientStaticGenerator = createReactGenerator({ } return ( - + { const meta = file.meta as any return item.key === meta?.pluginKey }) - const pluginOptions = plugin?.options as { output?: Output } + const pluginOptions = plugin?.options as { output?: Output } if (!pluginOptions || pluginOptions?.output?.barrelType === false) { return undefined diff --git a/packages/core/src/transformers/casing.ts b/packages/core/src/transformers/casing.ts index 2a623235a..c2c5976c8 100644 --- a/packages/core/src/transformers/casing.ts +++ b/packages/core/src/transformers/casing.ts @@ -15,7 +15,7 @@ export function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Op return splitArray.map((item, i) => (i === splitArray.length - 1 ? camelCase(item, { prefix, suffix }) : camelCase(item))).join('/') } - return _camelcase(`${prefix} ${text} ${suffix}`, { pascalCase: false, preserveConsecutiveUppercase: true }) + return _camelcase(`${prefix} ${text} ${suffix}`, { pascalCase: false, preserveConsecutiveUppercase: true }).replace(/[^a-zA-Z0-9]/g, '') } export function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string { @@ -24,5 +24,5 @@ export function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: O return splitArray.map((item, i) => (i === splitArray.length - 1 ? pascalCase(item, { prefix, suffix }) : camelCase(item))).join('/') } - return _camelcase(`${prefix} ${text} ${suffix}`, { pascalCase: true, preserveConsecutiveUppercase: true }) + return _camelcase(`${prefix} ${text} ${suffix}`, { pascalCase: true, preserveConsecutiveUppercase: true }).replace(/[^a-zA-Z0-9]/g, '') } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 21410f9d3..eec1946e5 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -291,7 +291,7 @@ export type PluginContext = { /** * Path to the output folder or file that will contain the generated code */ @@ -304,11 +304,11 @@ export type Output = { /** * Add a banner text in the beginning of every file */ - banner?: string + banner?: string | ((options: TOptions) => string) /** * Add a footer text in the beginning of every file */ - footer?: string + footer?: string | ((options: TOptions) => string) } type GroupContext = { diff --git a/packages/plugin-client/src/generators/clientGenerator.tsx b/packages/plugin-client/src/generators/clientGenerator.tsx index 4bebd771a..a9ef56ad9 100644 --- a/packages/plugin-client/src/generators/clientGenerator.tsx +++ b/packages/plugin-client/src/generators/clientGenerator.tsx @@ -1,5 +1,6 @@ import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -15,6 +16,7 @@ export const clientGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const client = { @@ -38,7 +40,13 @@ export const clientGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-client/src/generators/groupedClientGenerator.tsx b/packages/plugin-client/src/generators/groupedClientGenerator.tsx index 2dd37d132..7b204dbb7 100644 --- a/packages/plugin-client/src/generators/groupedClientGenerator.tsx +++ b/packages/plugin-client/src/generators/groupedClientGenerator.tsx @@ -1,8 +1,9 @@ import { camelCase } from '@kubb/core/transformers' import type * as KubbFile from '@kubb/fs/types' -import { pluginClientName } from '@kubb/plugin-client' + import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { File, Function, useApp } from '@kubb/react' import type { PluginClient } from '../types' @@ -13,6 +14,7 @@ export const groupedClientGenerator = createReactGenerator({ pluginManager, plugin: { options, key: pluginKey }, } = useApp() + const oas = useOas() const { getName, getFile, getGroup } = useOperationManager() const controllers = operations.reduce( @@ -53,7 +55,14 @@ export const groupedClientGenerator = createReactGenerator({ return controllers.map(({ name, file, clients }) => { return ( - + {clients.map((client) => ( ))} diff --git a/packages/plugin-client/src/generators/operationsGenerator.tsx b/packages/plugin-client/src/generators/operationsGenerator.tsx index 5b3433084..021cb92b2 100644 --- a/packages/plugin-client/src/generators/operationsGenerator.tsx +++ b/packages/plugin-client/src/generators/operationsGenerator.tsx @@ -1,5 +1,6 @@ -import { pluginClientName } from '@kubb/plugin-client' import { createReactGenerator } from '@kubb/plugin-oas' +import { useOas } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { File, useApp } from '@kubb/react' import { Operations } from '../components/Operations' import type { PluginClient } from '../types' @@ -14,12 +15,13 @@ export const operationsGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const name = 'operations' const file = pluginManager.getFile({ name, extname: '.ts', pluginKey }) return ( - + ) diff --git a/packages/plugin-client/src/types.ts b/packages/plugin-client/src/types.ts index 0f3469ee0..5e884a93d 100644 --- a/packages/plugin-client/src/types.ts +++ b/packages/plugin-client/src/types.ts @@ -1,5 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' +import type { Oas } from '@kubb/oas' import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas' export type Options = { @@ -7,7 +8,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'clients', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the clients based on the provided name. */ @@ -92,7 +93,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group?: Options['group'] baseURL: string | undefined parser: NonNullable diff --git a/packages/plugin-faker/src/generators/fakerGenerator.tsx b/packages/plugin-faker/src/generators/fakerGenerator.tsx index 506519c56..20b46dbe3 100644 --- a/packages/plugin-faker/src/generators/fakerGenerator.tsx +++ b/packages/plugin-faker/src/generators/fakerGenerator.tsx @@ -1,6 +1,7 @@ import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas' import { Oas } from '@kubb/plugin-oas/components' import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { File, useApp } from '@kubb/react' import { Faker } from '../components' @@ -76,7 +77,13 @@ export const fakerGenerator = createReactGenerator({ } return ( - + {regexGenerator === 'randexp' && } {dateParser !== 'faker' && } @@ -93,6 +100,7 @@ export const fakerGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const imports = getImports(schema.tree) const faker = { @@ -115,7 +123,13 @@ export const fakerGenerator = createReactGenerator({ ) return ( - + {regexGenerator === 'randexp' && } {dateParser !== 'faker' && } diff --git a/packages/plugin-faker/src/types.ts b/packages/plugin-faker/src/types.ts index f550c0047..b2fa19729 100644 --- a/packages/plugin-faker/src/types.ts +++ b/packages/plugin-faker/src/types.ts @@ -1,6 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { SchemaObject } from '@kubb/oas' +import type { Oas, SchemaObject } from '@kubb/oas' import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas' export type Options = { @@ -8,7 +8,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'handlers', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the Faker mocks based on the provided name. */ @@ -79,7 +79,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] override: NonNullable dateType: NonNullable diff --git a/packages/plugin-msw/src/generators/handlersGenerator.tsx b/packages/plugin-msw/src/generators/handlersGenerator.tsx index 35abfb9e0..6d50dde9b 100644 --- a/packages/plugin-msw/src/generators/handlersGenerator.tsx +++ b/packages/plugin-msw/src/generators/handlersGenerator.tsx @@ -1,14 +1,15 @@ import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { File, useApp } from '@kubb/react' import { Handlers } from '../components/Handlers.tsx' -import { pluginMswName } from '../plugin.ts' import type { PluginMsw } from '../types' export const handlersGenerator = createReactGenerator({ name: 'plugin-msw', Operations({ operations }) { const { pluginManager, plugin } = useApp() + const oas = useOas() const { getName, getFile } = useOperationManager() const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key }) @@ -23,7 +24,13 @@ export const handlersGenerator = createReactGenerator({ const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`) return ( - + {imports} diff --git a/packages/plugin-msw/src/generators/mswGenerator.tsx b/packages/plugin-msw/src/generators/mswGenerator.tsx index 0d5b9b736..5d6ece6f5 100644 --- a/packages/plugin-msw/src/generators/mswGenerator.tsx +++ b/packages/plugin-msw/src/generators/mswGenerator.tsx @@ -1,7 +1,8 @@ import { URLPath } from '@kubb/core/utils' import { pluginFakerName } from '@kubb/plugin-faker' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { File, useApp } from '@kubb/react' import { Mock, MockWithFaker } from '../components' @@ -15,6 +16,7 @@ export const mswGenerator = createReactGenerator({ options: { output, parser }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const mock = { @@ -33,7 +35,7 @@ export const mswGenerator = createReactGenerator({ } return ( - + diff --git a/packages/plugin-msw/src/types.ts b/packages/plugin-msw/src/types.ts index dbd1fa60f..f70ce4320 100644 --- a/packages/plugin-msw/src/types.ts +++ b/packages/plugin-msw/src/types.ts @@ -1,5 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' +import type { Oas } from '@kubb/oas' import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas' export type Options = { @@ -7,7 +8,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'mocks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the MSW mocks based on the provided name. */ @@ -48,7 +49,7 @@ export type Options = { generators?: Array> } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] parser: NonNullable } diff --git a/packages/plugin-oas/src/OperationGenerator.ts b/packages/plugin-oas/src/OperationGenerator.ts index aef50e15d..5f355b7b9 100644 --- a/packages/plugin-oas/src/OperationGenerator.ts +++ b/packages/plugin-oas/src/OperationGenerator.ts @@ -235,7 +235,7 @@ export class OperationGenerator< methods.forEach((method) => { const operation = oas.operation(path, method) - if (operation && [this.#methods].some((methods) => method === operation.method)) { + if (operation && method === operation.method) { const isExcluded = this.#isExcluded(operation, method) const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true diff --git a/packages/plugin-oas/src/generators/jsonGenerator.ts b/packages/plugin-oas/src/generators/jsonGenerator.ts index c31567343..3dd62b795 100644 --- a/packages/plugin-oas/src/generators/jsonGenerator.ts +++ b/packages/plugin-oas/src/generators/jsonGenerator.ts @@ -1,4 +1,5 @@ import { camelCase } from '@kubb/core/transformers' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { createGenerator } from '../generator.tsx' import type { PluginOas } from '../types.ts' @@ -24,8 +25,8 @@ export const jsonGenerator = createGenerator({ value: JSON.stringify(schema.value), }, ], - banner: plugin.options.output?.banner, - format: plugin.options.output?.footer, + banner: getBanner({ oas: instance.context.oas, output: plugin.options.output }), + format: getFooter({ oas: instance.context.oas, output: plugin.options.output }), }, ] }, diff --git a/packages/plugin-oas/src/types.ts b/packages/plugin-oas/src/types.ts index 35597f79d..7ce0e1b7b 100644 --- a/packages/plugin-oas/src/types.ts +++ b/packages/plugin-oas/src/types.ts @@ -32,7 +32,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'schemas', barrelType: 'named' } */ - output?: Output + output?: Output /** * Which server to use from the array of `servers.url[serverIndex]` * @example @@ -149,7 +149,7 @@ export type Override = (ByTag | ByOperationId | ByPath | ByMethod | By } type ResolvedOptions = Options & { - output: Output + output: Output } export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, API, never> diff --git a/packages/plugin-oas/src/utils/getBanner.ts b/packages/plugin-oas/src/utils/getBanner.ts new file mode 100644 index 000000000..52857ffa0 --- /dev/null +++ b/packages/plugin-oas/src/utils/getBanner.ts @@ -0,0 +1,20 @@ +import type { Output } from '@kubb/core' +import type { Oas } from '@kubb/oas' +import { isFunction } from 'remeda' + +type Props = { + oas: Oas + output: Output +} + +export function getBanner({ output, oas }: Props) { + if (!output.banner) { + return undefined + } + + if (isFunction(output.banner)) { + return output.banner(oas) + } + + return output.banner +} diff --git a/packages/plugin-oas/src/utils/getFooter.ts b/packages/plugin-oas/src/utils/getFooter.ts new file mode 100644 index 000000000..3070a00d5 --- /dev/null +++ b/packages/plugin-oas/src/utils/getFooter.ts @@ -0,0 +1,20 @@ +import type { Output } from '@kubb/core' +import type { Oas } from '@kubb/oas' +import { isFunction } from 'remeda' + +type Props = { + oas: Oas + output: Output +} + +export function getFooter({ output, oas }: Props) { + if (!output.footer) { + return undefined + } + + if (isFunction(output.footer)) { + return output.footer(oas) + } + + return output.footer +} diff --git a/packages/plugin-oas/src/utils/index.ts b/packages/plugin-oas/src/utils/index.ts index 99001f90e..92bc3e182 100644 --- a/packages/plugin-oas/src/utils/index.ts +++ b/packages/plugin-oas/src/utils/index.ts @@ -4,5 +4,7 @@ export { getSchemaFactory } from './getSchemaFactory.ts' export type { GetSchemasProps } from './getSchemas.ts' export { getSchemas } from './getSchemas.ts' export { parseFromConfig } from './parseFromConfig.ts' +export { getBanner } from './getBanner.ts' +export { getFooter } from './getFooter.ts' export { isOptional } from '@kubb/oas' diff --git a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx index 4787c3d91..32f99ca89 100644 --- a/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/infiniteQueryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const infiniteQueryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -61,7 +63,13 @@ export const infiniteQueryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-react-query/src/generators/mutationGenerator.tsx b/packages/plugin-react-query/src/generators/mutationGenerator.tsx index efbc44ecf..15bb5455b 100644 --- a/packages/plugin-react-query/src/generators/mutationGenerator.tsx +++ b/packages/plugin-react-query/src/generators/mutationGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const mutationGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) @@ -56,7 +58,13 @@ export const mutationGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-react-query/src/generators/queryGenerator.tsx b/packages/plugin-react-query/src/generators/queryGenerator.tsx index fa6551637..f549d63f1 100644 --- a/packages/plugin-react-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/queryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const queryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -61,7 +63,13 @@ export const queryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx index 8c969a2a7..da609d8ba 100644 --- a/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx +++ b/packages/plugin-react-query/src/generators/suspenseQueryGenerator.tsx @@ -1,7 +1,8 @@ import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -17,6 +18,7 @@ export const suspenseQueryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -63,7 +65,13 @@ export const suspenseQueryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-react-query/src/types.ts b/packages/plugin-react-query/src/types.ts index 0464c1920..6432ab752 100644 --- a/packages/plugin-react-query/src/types.ts +++ b/packages/plugin-react-query/src/types.ts @@ -1,6 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { HttpMethod, Operation } from '@kubb/oas' +import type { HttpMethod, Oas, Operation } from '@kubb/oas' import type { PluginClient } from '@kubb/plugin-client' import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas' @@ -78,7 +78,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'hooks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the @tanstack/query hooks based on the provided name. */ @@ -153,7 +153,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] client: Required, 'baseURL'>> & { baseURL?: string } parser: Required> diff --git a/packages/plugin-redoc/src/types.ts b/packages/plugin-redoc/src/types.ts index d0a0b88da..459a11b27 100644 --- a/packages/plugin-redoc/src/types.ts +++ b/packages/plugin-redoc/src/types.ts @@ -1,4 +1,5 @@ import type { Output, PluginFactoryOptions } from '@kubb/core' +import type { Oas } from '@kubb/oas' export type Options = { output?: { @@ -11,7 +12,7 @@ export type Options = { } type ResolveOptions = { - output: Output + output: Output } export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never> diff --git a/packages/plugin-solid-query/src/generators/queryGenerator.tsx b/packages/plugin-solid-query/src/generators/queryGenerator.tsx index 8434577f0..cd432bcd7 100644 --- a/packages/plugin-solid-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-solid-query/src/generators/queryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const queryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -57,7 +59,13 @@ export const queryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-solid-query/src/types.ts b/packages/plugin-solid-query/src/types.ts index 5c2cfb41c..23c1db7c2 100644 --- a/packages/plugin-solid-query/src/types.ts +++ b/packages/plugin-solid-query/src/types.ts @@ -1,6 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { HttpMethod, Operation } from '@kubb/oas' +import type { HttpMethod, Oas, Operation } from '@kubb/oas' import type { PluginClient } from '@kubb/plugin-client' import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas' import type { PluginReactQuery } from '@kubb/plugin-react-query' @@ -39,7 +39,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'hooks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the @tanstack/query hooks based on the provided name. */ @@ -100,7 +100,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] client: Required, 'baseURL'>> & { baseURL?: string } parser: Required> diff --git a/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx b/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx index f310cbdba..ac4271642 100644 --- a/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx +++ b/packages/plugin-svelte-query/src/generators/mutationGenerator.tsx @@ -1,7 +1,8 @@ import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -17,6 +18,7 @@ export const mutationGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) @@ -57,7 +59,13 @@ export const mutationGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-svelte-query/src/generators/queryGenerator.tsx b/packages/plugin-svelte-query/src/generators/queryGenerator.tsx index 02f8a24e5..e9077c974 100644 --- a/packages/plugin-svelte-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-svelte-query/src/generators/queryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const queryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -59,7 +61,13 @@ export const queryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-svelte-query/src/types.ts b/packages/plugin-svelte-query/src/types.ts index 2183d9090..c6077bd23 100644 --- a/packages/plugin-svelte-query/src/types.ts +++ b/packages/plugin-svelte-query/src/types.ts @@ -1,6 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { HttpMethod, Operation } from '@kubb/oas' +import type { HttpMethod, Oas, Operation } from '@kubb/oas' import type { PluginClient } from '@kubb/plugin-client' import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas' import type { PluginReactQuery } from '@kubb/plugin-react-query' @@ -60,7 +60,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'hooks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the @tanstack/query hooks based on the provided name. */ @@ -127,7 +127,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] client: Required, 'baseURL'>> & { baseURL?: string } parser: Required> diff --git a/packages/plugin-swr/src/generators/mutationGenerator.tsx b/packages/plugin-swr/src/generators/mutationGenerator.tsx index fb37ca748..438379186 100644 --- a/packages/plugin-swr/src/generators/mutationGenerator.tsx +++ b/packages/plugin-swr/src/generators/mutationGenerator.tsx @@ -1,7 +1,7 @@ -import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -18,6 +18,7 @@ export const mutationGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) @@ -58,7 +59,13 @@ export const mutationGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-swr/src/generators/queryGenerator.tsx b/packages/plugin-swr/src/generators/queryGenerator.tsx index 7be56cad6..9a262e7f9 100644 --- a/packages/plugin-swr/src/generators/queryGenerator.tsx +++ b/packages/plugin-swr/src/generators/queryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -17,6 +18,7 @@ export const queryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -59,7 +61,13 @@ export const queryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-swr/src/types.ts b/packages/plugin-swr/src/types.ts index 2c0c8ceda..dcae5be78 100644 --- a/packages/plugin-swr/src/types.ts +++ b/packages/plugin-swr/src/types.ts @@ -1,5 +1,5 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { HttpMethod, Operation } from '@kubb/oas' +import type { HttpMethod, Oas, Operation } from '@kubb/oas' import type { PluginClient } from '@kubb/plugin-client' import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas' import type { PluginReactQuery } from '@kubb/plugin-react-query' @@ -59,7 +59,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'hooks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the SWR hooks based on the provided name. */ @@ -118,7 +118,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output client: Required, 'baseURL'>> & { baseURL?: string } parser: Required> queryKey: QueryKey | undefined diff --git a/packages/plugin-ts/src/generators/oasGenerator.tsx b/packages/plugin-ts/src/generators/oasGenerator.tsx index 1199f2192..38a9b1725 100644 --- a/packages/plugin-ts/src/generators/oasGenerator.tsx +++ b/packages/plugin-ts/src/generators/oasGenerator.tsx @@ -1,5 +1,6 @@ import { createReactGenerator } from '@kubb/plugin-oas' import { useOas } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { File, useApp } from '@kubb/react' import { OasType } from '../components' import type { PluginTs } from '../types.ts' @@ -19,7 +20,7 @@ export const oasGenerator = createReactGenerator({ const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey }) return ( - + diff --git a/packages/plugin-ts/src/generators/typeGenerator.tsx b/packages/plugin-ts/src/generators/typeGenerator.tsx index 5c44afa3f..2ad541c20 100644 --- a/packages/plugin-ts/src/generators/typeGenerator.tsx +++ b/packages/plugin-ts/src/generators/typeGenerator.tsx @@ -5,6 +5,7 @@ import * as factory from '@kubb/parser-ts/factory' import { type OperationSchema as OperationSchemaType, type OperationSchemas, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas' import { Oas } from '@kubb/plugin-oas/components' import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { File, useApp } from '@kubb/react' import type ts from 'typescript' @@ -158,7 +159,13 @@ export const typeGenerator = createReactGenerator({ } return ( - + {operationSchemas.map(mapOperationSchema)} @@ -175,6 +182,7 @@ export const typeGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getName, getImports, getFile } = useSchemaManager() const imports = getImports(schema.tree) @@ -190,7 +198,7 @@ export const typeGenerator = createReactGenerator({ } return ( - + {mode === 'split' && imports.map((imp, index) => )} /** * Group the clients based on the provided name. */ @@ -86,7 +87,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] override: NonNullable enumType: NonNullable diff --git a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx index 0bd18e872..4bebbf5a4 100644 --- a/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx +++ b/packages/plugin-vue-query/src/generators/infiniteQueryGenerator.tsx @@ -1,7 +1,7 @@ -import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -17,6 +17,7 @@ export const infiniteQueryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -61,7 +62,13 @@ export const infiniteQueryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-vue-query/src/generators/mutationGenerator.tsx b/packages/plugin-vue-query/src/generators/mutationGenerator.tsx index db9dc109c..abcf4dca4 100644 --- a/packages/plugin-vue-query/src/generators/mutationGenerator.tsx +++ b/packages/plugin-vue-query/src/generators/mutationGenerator.tsx @@ -1,7 +1,8 @@ import { pluginClientName } from '@kubb/plugin-client' import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -17,6 +18,7 @@ export const mutationGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method) @@ -57,7 +59,13 @@ export const mutationGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-vue-query/src/generators/queryGenerator.tsx b/packages/plugin-vue-query/src/generators/queryGenerator.tsx index d10fc3326..35461473b 100644 --- a/packages/plugin-vue-query/src/generators/queryGenerator.tsx +++ b/packages/plugin-vue-query/src/generators/queryGenerator.tsx @@ -1,6 +1,7 @@ import { Client } from '@kubb/plugin-client/components' import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +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, useApp } from '@kubb/react' @@ -16,6 +17,7 @@ export const queryGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getSchemas, getName, getFile } = useOperationManager() const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method) @@ -59,7 +61,13 @@ export const queryGenerator = createReactGenerator({ } return ( - + {options.parser === 'zod' && } diff --git a/packages/plugin-vue-query/src/types.ts b/packages/plugin-vue-query/src/types.ts index 00939aa18..37c566aa2 100644 --- a/packages/plugin-vue-query/src/types.ts +++ b/packages/plugin-vue-query/src/types.ts @@ -1,6 +1,6 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { HttpMethod, Operation } from '@kubb/oas' +import type { HttpMethod, Oas, Operation } from '@kubb/oas' import type { PluginClient } from '@kubb/plugin-client' import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas' import type { PluginReactQuery } from '@kubb/plugin-react-query' @@ -77,7 +77,7 @@ export type Options = { * Specify the export location for the files and define the behavior of the output * @default { path: 'hooks', barrelType: 'named' } */ - output?: Output + output?: Output /** * Group the @tanstack/query hooks based on the provided name. */ @@ -147,7 +147,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] client: Required, 'baseURL'>> & { baseURL?: string } parser: Required> diff --git a/packages/plugin-zod/src/generators/operationsGenerator.tsx b/packages/plugin-zod/src/generators/operationsGenerator.tsx index 89a07a750..f35f9a8bb 100644 --- a/packages/plugin-zod/src/generators/operationsGenerator.tsx +++ b/packages/plugin-zod/src/generators/operationsGenerator.tsx @@ -1,8 +1,8 @@ import { createReactGenerator } from '@kubb/plugin-oas' -import { useOperationManager } from '@kubb/plugin-oas/hooks' +import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { File, useApp } from '@kubb/react' import { Operations } from '../components/Operations' -import { pluginZodName } from '../plugin.ts' import type { PluginZod } from '../types' export const operationsGenerator = createReactGenerator({ @@ -15,6 +15,7 @@ export const operationsGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const { getFile, groupSchemasByName } = useOperationManager() const name = 'operations' @@ -31,7 +32,7 @@ export const operationsGenerator = createReactGenerator({ .filter(Boolean) return ( - + {imports} diff --git a/packages/plugin-zod/src/generators/zodGenerator.tsx b/packages/plugin-zod/src/generators/zodGenerator.tsx index 0cceaa5ea..3ff540352 100644 --- a/packages/plugin-zod/src/generators/zodGenerator.tsx +++ b/packages/plugin-zod/src/generators/zodGenerator.tsx @@ -1,6 +1,7 @@ import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas' import { Oas } from '@kubb/plugin-oas/components' import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks' +import { getBanner, getFooter } from '@kubb/plugin-oas/utils' import { pluginTsName } from '@kubb/plugin-ts' import { File, useApp } from '@kubb/react' import { Zod } from '../components' @@ -71,7 +72,13 @@ export const zodGenerator = createReactGenerator({ } return ( - + {operationSchemas.map(mapOperationSchema)} @@ -86,6 +93,7 @@ export const zodGenerator = createReactGenerator({ options: { output }, }, } = useApp() + const oas = useOas() const imports = getImports(schema.tree) @@ -101,7 +109,7 @@ export const zodGenerator = createReactGenerator({ } return ( - + {typed && } {typed && } diff --git a/packages/plugin-zod/src/types.ts b/packages/plugin-zod/src/types.ts index df422a88d..d5e8cb465 100644 --- a/packages/plugin-zod/src/types.ts +++ b/packages/plugin-zod/src/types.ts @@ -1,12 +1,12 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core' -import type { SchemaObject } from '@kubb/oas' +import type { Oas, SchemaObject } from '@kubb/oas' import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas' export type Options = { /** * @default 'zod' */ - output?: Output + output?: Output /** * Group the Zod schemas based on the provided name. */ @@ -90,7 +90,7 @@ export type Options = { } type ResolvedOptions = { - output: Output + output: Output group: Options['group'] override: NonNullable transformers: NonNullable