Skip to content

Commit 50fa150

Browse files
authored
bug fixes PR 1680 (#1693)
Co-authored-by: grumpytofu <>
1 parent 75fe971 commit 50fa150

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

packages/rtk-query-codegen-openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@rtk-query/codgen-openapi",
2+
"name": "@rtk-query/codegen-openapi",
33
"version": "1.0.0-alpha.1",
44
"main": "lib/index.js",
55
"types": "lib/index.d.ts",

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { generateCreateApiCall, generateEndpointDefinition, generateImportNode }
2222

2323
const { factory } = ts;
2424

25+
const generatedApiName = 'injectedRtkApi';
26+
2527
function defaultIsDataResponse(code: string) {
2628
const parsedCode = Number(code);
2729
return !Number.isNaN(parsedCode) && parsedCode >= 200 && parsedCode < 300;
@@ -119,13 +121,18 @@ export async function generateApi(
119121
undefined,
120122
false,
121123
factory.createNamedExports([
122-
factory.createExportSpecifier(factory.createIdentifier('injectedRtkApi'), factory.createIdentifier('api')),
124+
factory.createExportSpecifier(
125+
factory.createIdentifier(generatedApiName),
126+
factory.createIdentifier(exportName)
127+
),
123128
]),
124129
undefined
125130
),
126131
...Object.values(interfaces),
127132
...apiGen['aliases'],
128-
...(hooks ? [generateReactHooks({ exportName, operationDefinitions, endpointOverrides })] : []),
133+
...(hooks
134+
? [generateReactHooks({ exportName: generatedApiName, operationDefinitions, endpointOverrides })]
135+
: []),
129136
],
130137
factory.createToken(ts.SyntaxKind.EndOfFileToken),
131138
ts.NodeFlags.None

packages/rtk-query-codegen-openapi/test/__snapshots__/cli.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const injectedRtkApi = api.injectEndpoints({
7676
}),
7777
overrideExisting: false,
7878
});
79-
export { injectedRtkApi as api };
79+
export { injectedRtkApi as enhancedApi };
8080
export type UpdatePetApiResponse = /** status 200 Successful operation */ Pet;
8181
export type UpdatePetApiArg = {
8282
/** Update an existent pet in the store */

packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const injectedRtkApi = api.injectEndpoints({
115115
}),
116116
overrideExisting: false,
117117
});
118-
export { injectedRtkApi as api };
118+
export { injectedRtkApi as enhancedApi };
119119
export type GetHealthcheckApiResponse = /** status 200 OK */ {
120120
message: string;
121121
};
@@ -292,7 +292,7 @@ const injectedRtkApi = api.injectEndpoints({
292292
}),
293293
overrideExisting: false,
294294
});
295-
export { injectedRtkApi as api };
295+
export { injectedRtkApi as enhancedApi };
296296
export type PlaceOrderApiResponse = /** status 200 successful operation */ Order;
297297
export type PlaceOrderApiArg = {
298298
order: Order;
@@ -339,7 +339,7 @@ const injectedRtkApi = api.injectEndpoints({
339339
}),
340340
overrideExisting: false,
341341
});
342-
export { injectedRtkApi as api };
342+
export { injectedRtkApi as enhancedApi };
343343
export type LoginUserApiResponse = /** status 200 successful operation */ string;
344344
export type LoginUserApiArg = {
345345
/** The user name for login */
@@ -364,15 +364,15 @@ const injectedRtkApi = api.injectEndpoints({
364364
}),
365365
overrideExisting: false,
366366
});
367-
export { injectedRtkApi as api };
367+
export { injectedRtkApi as enhancedApi };
368368
export type LoginUserApiResponse = /** status 200 successful operation */ string;
369369
export type LoginUserApiArg = {
370370
/** The user name for login */
371371
username?: string;
372372
/** The password for login in clear text */
373373
password?: string;
374374
};
375-
export const { useLoginUserMutation } = enhancedApi;
375+
export const { useLoginUserMutation } = injectedRtkApi;
376376

377377
`;
378378

@@ -393,7 +393,7 @@ const injectedRtkApi = api.injectEndpoints({
393393
}),
394394
overrideExisting: false,
395395
});
396-
export { injectedRtkApi as api };
396+
export { injectedRtkApi as enhancedApi };
397397
export type AddPetApiResponse = /** status 200 Successful operation */ Pet;
398398
export type AddPetApiArg = {
399399
/** Create a new pet in the store */
@@ -420,7 +420,7 @@ export type Pet = {
420420
tags?: Tag[];
421421
status?: 'available' | 'pending' | 'sold';
422422
};
423-
export const { useAddPetMutation, useGetPetByIdQuery } = enhancedApi;
423+
export const { useAddPetMutation, useGetPetByIdQuery } = injectedRtkApi;
424424

425425
`;
426426

@@ -437,7 +437,7 @@ const injectedRtkApi = api.injectEndpoints({
437437
}),
438438
overrideExisting: false,
439439
});
440-
export { injectedRtkApi as api };
440+
export { injectedRtkApi as enhancedApi };
441441
export type PatchApiV1ListByItemIdApiResponse = /** status 200 A successful response. */ string;
442442
export type PatchApiV1ListByItemIdApiArg = {
443443
'item.id': string;
@@ -557,7 +557,7 @@ const injectedRtkApi = api.injectEndpoints({
557557
}),
558558
overrideExisting: false,
559559
});
560-
export { injectedRtkApi as api };
560+
export { injectedRtkApi as enhancedApi };
561561
export type UpdatePetApiResponse = /** status 200 Successful operation */ Pet;
562562
export type UpdatePetApiArg = {
563563
/** Update an existent pet in the store */
@@ -718,7 +718,7 @@ export const {
718718
useGetUserByNameQuery,
719719
useUpdateUserMutation,
720720
useDeleteUserMutation,
721-
} = enhancedApi;
721+
} = injectedRtkApi;
722722

723723
`;
724724

@@ -744,7 +744,7 @@ const injectedRtkApi = api.injectEndpoints({
744744
}),
745745
overrideExisting: false,
746746
});
747-
export { injectedRtkApi as api };
747+
export { injectedRtkApi as enhancedApi };
748748
export type GetStructureDefinitionApiResponse = unknown;
749749
export type GetStructureDefinitionApiArg = {
750750
/** Some description */
@@ -764,7 +764,7 @@ export type GetStructureDefinitionApiArg = {
764764
/** Some description */
765765
naming_conflict?: any;
766766
};
767-
export const { useGetStructureDefinitionQuery } = enhancedApi;
767+
export const { useGetStructureDefinitionQuery } = injectedRtkApi;
768768

769769
`;
770770

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6156,9 +6156,9 @@ __metadata:
61566156
languageName: unknown
61576157
linkType: soft
61586158

6159-
"@rtk-query/codgen-openapi@workspace:packages/rtk-query-codegen-openapi":
6159+
"@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi":
61606160
version: 0.0.0-use.local
6161-
resolution: "@rtk-query/codgen-openapi@workspace:packages/rtk-query-codegen-openapi"
6161+
resolution: "@rtk-query/codegen-openapi@workspace:packages/rtk-query-codegen-openapi"
61626162
dependencies:
61636163
"@apidevtools/swagger-parser": ^10.0.2
61646164
"@babel/core": ^7.12.10

0 commit comments

Comments
 (0)