diff --git a/plugins/typescript/src/generators/generateFetchers.ts b/plugins/typescript/src/generators/generateFetchers.ts index 7e5ce6f8..f829374e 100644 --- a/plugins/typescript/src/generators/generateFetchers.ts +++ b/plugins/typescript/src/generators/generateFetchers.ts @@ -65,7 +65,12 @@ export const generateFetchers = async (context: Context, config: Config) => { const filenamePrefix = c.snake(config.filenamePrefix ?? context.openAPIDocument.info.title) + "-"; - const formatFilename = config.filenameCase ? c[config.filenameCase] : c.camel; + const formatFilename = + typeof config.formatFilename === "function" + ? config.formatFilename + : config.filenameCase + ? c[config.filenameCase] + : c.camel; const filename = formatFilename(filenamePrefix + "-components"); diff --git a/plugins/typescript/src/generators/generateReactQueryComponents.ts b/plugins/typescript/src/generators/generateReactQueryComponents.ts index 99887fd3..df1ca2d2 100644 --- a/plugins/typescript/src/generators/generateReactQueryComponents.ts +++ b/plugins/typescript/src/generators/generateReactQueryComponents.ts @@ -70,7 +70,12 @@ export const generateReactQueryComponents = async ( const filenamePrefix = c.snake(config.filenamePrefix ?? context.openAPIDocument.info.title) + "-"; - const formatFilename = config.filenameCase ? c[config.filenameCase] : c.camel; + const formatFilename = + typeof config.formatFilename === "function" + ? config.formatFilename + : config.filenameCase + ? c[config.filenameCase] + : c.camel; const filename = formatFilename(filenamePrefix + "-components"); diff --git a/plugins/typescript/src/generators/generateReactQueryFunctions.ts b/plugins/typescript/src/generators/generateReactQueryFunctions.ts index 65a43898..e5ca827b 100644 --- a/plugins/typescript/src/generators/generateReactQueryFunctions.ts +++ b/plugins/typescript/src/generators/generateReactQueryFunctions.ts @@ -72,7 +72,12 @@ export const generateReactQueryFunctions = async ( const filenamePrefix = c.snake(config.filenamePrefix ?? context.openAPIDocument.info.title) + "-"; - const formatFilename = config.filenameCase ? c[config.filenameCase] : c.camel; + const formatFilename = + typeof config.formatFilename === "function" + ? config.formatFilename + : config.filenameCase + ? c[config.filenameCase] + : c.camel; const filename = formatFilename(filenamePrefix + "-functions"); @@ -143,8 +148,6 @@ export const generateReactQueryFunctions = async ( ), }); - - const operationFetcherFnName = `fetch${c.pascal(operationId)}`; const operationQueryFnName = `${c.pascal(operationId)}Query`; const component: "useQuery" | "useMutate" = @@ -157,7 +160,6 @@ export const generateReactQueryFunctions = async ( } if (component === "useQuery") { - nodes.push(...declarationNodes); keyManagerItems.push( diff --git a/plugins/typescript/src/generators/generateSchemaTypes.ts b/plugins/typescript/src/generators/generateSchemaTypes.ts index 14a32de9..ad0fbee3 100644 --- a/plugins/typescript/src/generators/generateSchemaTypes.ts +++ b/plugins/typescript/src/generators/generateSchemaTypes.ts @@ -72,7 +72,12 @@ export const generateSchemaTypes = async ( const filenamePrefix = c.snake(config.filenamePrefix ?? context.openAPIDocument.info.title) + "-"; - const formatFilename = config.filenameCase ? c[config.filenameCase] : c.camel; + const formatFilename = + typeof config.formatFilename === "function" + ? config.formatFilename + : config.filenameCase + ? c[config.filenameCase] + : c.camel; const files = { requestBodies: formatFilename(filenamePrefix + "-request-bodies"), schemas: formatFilename(filenamePrefix + "-schemas"), diff --git a/plugins/typescript/src/generators/types.ts b/plugins/typescript/src/generators/types.ts index 18708fca..b3d968ed 100644 --- a/plugins/typescript/src/generators/types.ts +++ b/plugins/typescript/src/generators/types.ts @@ -25,6 +25,11 @@ export type ConfigBase = { * @default camel */ filenameCase?: keyof Pick; + /** + * Allows customizing the filename. + * If provided, `filenameCase` will be ignored. + */ + formatFilename?: (filename: string) => string; /** * Allows using explicit enums instead of string unions. *