Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added config formatFilename to allow more custom formatting of filenames #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/typescript/src/generators/generateFetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
10 changes: 6 additions & 4 deletions plugins/typescript/src/generators/generateReactQueryFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -143,8 +148,6 @@ export const generateReactQueryFunctions = async (
),
});



const operationFetcherFnName = `fetch${c.pascal(operationId)}`;
const operationQueryFnName = `${c.pascal(operationId)}Query`;
const component: "useQuery" | "useMutate" =
Expand All @@ -157,7 +160,6 @@ export const generateReactQueryFunctions = async (
}

if (component === "useQuery") {

nodes.push(...declarationNodes);

keyManagerItems.push(
Expand Down
7 changes: 6 additions & 1 deletion plugins/typescript/src/generators/generateSchemaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 5 additions & 0 deletions plugins/typescript/src/generators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export type ConfigBase = {
* @default camel
*/
filenameCase?: keyof Pick<typeof c, "snake" | "camel" | "kebab" | "pascal">;
/**
* Allows customizing the filename.
* If provided, `filenameCase` will be ignored.
*/
formatFilename?: (filename: string) => string;
/**
* Allows using explicit enums instead of string unions.
*
Expand Down