Skip to content

Commit 5bd39b0

Browse files
Георгиев Антон Стоев (4084897)markerikson
Георгиев Антон Стоев (4084897)
authored andcommitted
Codegen: add operation name suffix
1 parent be6f9a6 commit 5bd39b0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

docs/rtk-query/usage/code-generation.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ interface SimpleUsage {
9595
apiImport?: string
9696
exportName?: string
9797
argSuffix?: string
98+
operationNameSuffix?: string
9899
responseSuffix?: string
99100
hooks?:
100101
| boolean

packages/rtk-query-codegen-openapi/src/generate.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export async function generateApi(
102102
exportName = 'enhancedApi',
103103
argSuffix = 'ApiArg',
104104
responseSuffix = 'ApiResponse',
105+
operationNameSuffix = '',
105106
hooks = false,
106107
tag = false,
107108
outputFile,
@@ -271,7 +272,7 @@ export async function generateApi(
271272
registerInterface(
272273
factory.createTypeAliasDeclaration(
273274
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
274-
capitalize(operationName + responseSuffix),
275+
capitalize(operationName + operationNameSuffix + responseSuffix),
275276
undefined,
276277
ResponseType
277278
)
@@ -356,7 +357,7 @@ export async function generateApi(
356357
registerInterface(
357358
factory.createTypeAliasDeclaration(
358359
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
359-
capitalize(operationName + argSuffix),
360+
capitalize(operationName + operationNameSuffix + argSuffix),
360361
undefined,
361362
queryArgValues.length > 0
362363
? isFlatArg
@@ -390,7 +391,7 @@ export async function generateApi(
390391
);
391392

392393
return generateEndpointDefinition({
393-
operationName,
394+
operationName: operationNameSuffix ? capitalize(operationName + operationNameSuffix) : operationName,
394395
type: isQuery ? 'query' : 'mutation',
395396
Response: ResponseTypeName,
396397
QueryArg,

packages/rtk-query-codegen-openapi/src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export interface CommonOptions {
5252
* defaults to "ApiResponse"
5353
*/
5454
responseSuffix?: string;
55+
/**
56+
* defaults to empty
57+
*/
58+
operationNameSuffix?: string;
5559
/**
5660
* defaults to `false`
5761
* `true` will generate hooks for queries and mutations, but no lazyQueries

0 commit comments

Comments
 (0)