Skip to content

Commit 6b1f11d

Browse files
committed
Add operation suffix test
1 parent 5bd39b0 commit 6b1f11d

File tree

2 files changed

+329
-0
lines changed

2 files changed

+329
-0
lines changed

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

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,323 @@ export type ExampleSchemaWrite = {
25242524
"
25252525
`;
25262526

2527+
exports[`operation suffixes are applied 1`] = `
2528+
"import { api } from "./fixtures/emptyApi";
2529+
const injectedRtkApi = api.injectEndpoints({
2530+
endpoints: (build) => ({
2531+
GetHealthcheckV2: build.query<
2532+
GetHealthcheckV2ApiResponse,
2533+
GetHealthcheckV2ApiArg
2534+
>({
2535+
query: () => ({ url: \`/healthcheck\` }),
2536+
}),
2537+
UpdatePetV2: build.mutation<UpdatePetV2ApiResponse, UpdatePetV2ApiArg>({
2538+
query: (queryArg) => ({ url: \`/pet\`, method: "PUT", body: queryArg.pet }),
2539+
}),
2540+
AddPetV2: build.mutation<AddPetV2ApiResponse, AddPetV2ApiArg>({
2541+
query: (queryArg) => ({
2542+
url: \`/pet\`,
2543+
method: "POST",
2544+
body: queryArg.pet,
2545+
}),
2546+
}),
2547+
FindPetsByStatusV2: build.query<
2548+
FindPetsByStatusV2ApiResponse,
2549+
FindPetsByStatusV2ApiArg
2550+
>({
2551+
query: (queryArg) => ({
2552+
url: \`/pet/findByStatus\`,
2553+
params: {
2554+
status: queryArg.status,
2555+
},
2556+
}),
2557+
}),
2558+
FindPetsByTagsV2: build.query<
2559+
FindPetsByTagsV2ApiResponse,
2560+
FindPetsByTagsV2ApiArg
2561+
>({
2562+
query: (queryArg) => ({
2563+
url: \`/pet/findByTags\`,
2564+
params: {
2565+
tags: queryArg.tags,
2566+
},
2567+
}),
2568+
}),
2569+
GetPetByIdV2: build.query<GetPetByIdV2ApiResponse, GetPetByIdV2ApiArg>({
2570+
query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }),
2571+
}),
2572+
UpdatePetWithFormV2: build.mutation<
2573+
UpdatePetWithFormV2ApiResponse,
2574+
UpdatePetWithFormV2ApiArg
2575+
>({
2576+
query: (queryArg) => ({
2577+
url: \`/pet/\${queryArg.petId}\`,
2578+
method: "POST",
2579+
params: {
2580+
name: queryArg.name,
2581+
status: queryArg.status,
2582+
},
2583+
}),
2584+
}),
2585+
DeletePetV2: build.mutation<DeletePetV2ApiResponse, DeletePetV2ApiArg>({
2586+
query: (queryArg) => ({
2587+
url: \`/pet/\${queryArg.petId}\`,
2588+
method: "DELETE",
2589+
headers: {
2590+
api_key: queryArg.apiKey,
2591+
},
2592+
}),
2593+
}),
2594+
UploadFileV2: build.mutation<UploadFileV2ApiResponse, UploadFileV2ApiArg>({
2595+
query: (queryArg) => ({
2596+
url: \`/pet/\${queryArg.petId}/uploadImage\`,
2597+
method: "POST",
2598+
body: queryArg.body,
2599+
params: {
2600+
additionalMetadata: queryArg.additionalMetadata,
2601+
},
2602+
}),
2603+
}),
2604+
GetInventoryV2: build.query<
2605+
GetInventoryV2ApiResponse,
2606+
GetInventoryV2ApiArg
2607+
>({
2608+
query: () => ({ url: \`/store/inventory\` }),
2609+
}),
2610+
PlaceOrderV2: build.mutation<PlaceOrderV2ApiResponse, PlaceOrderV2ApiArg>({
2611+
query: (queryArg) => ({
2612+
url: \`/store/order\`,
2613+
method: "POST",
2614+
body: queryArg.order,
2615+
}),
2616+
}),
2617+
GetOrderByIdV2: build.query<
2618+
GetOrderByIdV2ApiResponse,
2619+
GetOrderByIdV2ApiArg
2620+
>({
2621+
query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\` }),
2622+
}),
2623+
DeleteOrderV2: build.mutation<
2624+
DeleteOrderV2ApiResponse,
2625+
DeleteOrderV2ApiArg
2626+
>({
2627+
query: (queryArg) => ({
2628+
url: \`/store/order/\${queryArg.orderId}\`,
2629+
method: "DELETE",
2630+
}),
2631+
}),
2632+
CreateUserV2: build.mutation<CreateUserV2ApiResponse, CreateUserV2ApiArg>({
2633+
query: (queryArg) => ({
2634+
url: \`/user\`,
2635+
method: "POST",
2636+
body: queryArg.user,
2637+
}),
2638+
}),
2639+
CreateUsersWithListInputV2: build.mutation<
2640+
CreateUsersWithListInputV2ApiResponse,
2641+
CreateUsersWithListInputV2ApiArg
2642+
>({
2643+
query: (queryArg) => ({
2644+
url: \`/user/createWithList\`,
2645+
method: "POST",
2646+
body: queryArg.body,
2647+
}),
2648+
}),
2649+
LoginUserV2: build.query<LoginUserV2ApiResponse, LoginUserV2ApiArg>({
2650+
query: (queryArg) => ({
2651+
url: \`/user/login\`,
2652+
params: {
2653+
username: queryArg.username,
2654+
password: queryArg.password,
2655+
},
2656+
}),
2657+
}),
2658+
LogoutUserV2: build.query<LogoutUserV2ApiResponse, LogoutUserV2ApiArg>({
2659+
query: () => ({ url: \`/user/logout\` }),
2660+
}),
2661+
GetUserByNameV2: build.query<
2662+
GetUserByNameV2ApiResponse,
2663+
GetUserByNameV2ApiArg
2664+
>({
2665+
query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }),
2666+
}),
2667+
UpdateUserV2: build.mutation<UpdateUserV2ApiResponse, UpdateUserV2ApiArg>({
2668+
query: (queryArg) => ({
2669+
url: \`/user/\${queryArg.username}\`,
2670+
method: "PUT",
2671+
body: queryArg.user,
2672+
}),
2673+
}),
2674+
DeleteUserV2: build.mutation<DeleteUserV2ApiResponse, DeleteUserV2ApiArg>({
2675+
query: (queryArg) => ({
2676+
url: \`/user/\${queryArg.username}\`,
2677+
method: "DELETE",
2678+
}),
2679+
}),
2680+
}),
2681+
overrideExisting: false,
2682+
});
2683+
export { injectedRtkApi as enhancedApi };
2684+
export type GetHealthcheckV2ApiResponse = /** status 200 OK */ {
2685+
message: string;
2686+
};
2687+
export type GetHealthcheckV2ApiArg = void;
2688+
export type UpdatePetV2ApiResponse = /** status 200 Successful operation */ Pet;
2689+
export type UpdatePetV2ApiArg = {
2690+
/** Update an existent pet in the store */
2691+
pet: Pet;
2692+
};
2693+
export type AddPetV2ApiResponse = /** status 200 Successful operation */ Pet;
2694+
export type AddPetV2ApiArg = {
2695+
/** Create a new pet in the store */
2696+
pet: Pet;
2697+
};
2698+
export type FindPetsByStatusV2ApiResponse =
2699+
/** status 200 successful operation */ Pet[];
2700+
export type FindPetsByStatusV2ApiArg = {
2701+
/** Status values that need to be considered for filter */
2702+
status?: "available" | "pending" | "sold";
2703+
};
2704+
export type FindPetsByTagsV2ApiResponse =
2705+
/** status 200 successful operation */ Pet[];
2706+
export type FindPetsByTagsV2ApiArg = {
2707+
/** Tags to filter by */
2708+
tags?: string[];
2709+
};
2710+
export type GetPetByIdV2ApiResponse =
2711+
/** status 200 successful operation */ Pet;
2712+
export type GetPetByIdV2ApiArg = {
2713+
/** ID of pet to return */
2714+
petId: number;
2715+
};
2716+
export type UpdatePetWithFormV2ApiResponse = unknown;
2717+
export type UpdatePetWithFormV2ApiArg = {
2718+
/** ID of pet that needs to be updated */
2719+
petId: number;
2720+
/** Name of pet that needs to be updated */
2721+
name?: string;
2722+
/** Status of pet that needs to be updated */
2723+
status?: string;
2724+
};
2725+
export type DeletePetV2ApiResponse = unknown;
2726+
export type DeletePetV2ApiArg = {
2727+
apiKey?: string;
2728+
/** Pet id to delete */
2729+
petId: number;
2730+
};
2731+
export type UploadFileV2ApiResponse =
2732+
/** status 200 successful operation */ ApiResponse;
2733+
export type UploadFileV2ApiArg = {
2734+
/** ID of pet to update */
2735+
petId: number;
2736+
/** Additional Metadata */
2737+
additionalMetadata?: string;
2738+
body: Blob;
2739+
};
2740+
export type GetInventoryV2ApiResponse = /** status 200 successful operation */ {
2741+
[key: string]: number;
2742+
};
2743+
export type GetInventoryV2ApiArg = void;
2744+
export type PlaceOrderV2ApiResponse =
2745+
/** status 200 successful operation */ Order;
2746+
export type PlaceOrderV2ApiArg = {
2747+
order: Order;
2748+
};
2749+
export type GetOrderByIdV2ApiResponse =
2750+
/** status 200 successful operation */ Order;
2751+
export type GetOrderByIdV2ApiArg = {
2752+
/** ID of order that needs to be fetched */
2753+
orderId: number;
2754+
};
2755+
export type DeleteOrderV2ApiResponse = unknown;
2756+
export type DeleteOrderV2ApiArg = {
2757+
/** ID of the order that needs to be deleted */
2758+
orderId: number;
2759+
};
2760+
export type CreateUserV2ApiResponse =
2761+
/** status default successful operation */ User;
2762+
export type CreateUserV2ApiArg = {
2763+
/** Created user object */
2764+
user: User;
2765+
};
2766+
export type CreateUsersWithListInputV2ApiResponse =
2767+
/** status 200 Successful operation */ User;
2768+
export type CreateUsersWithListInputV2ApiArg = {
2769+
body: User[];
2770+
};
2771+
export type LoginUserV2ApiResponse =
2772+
/** status 200 successful operation */ string;
2773+
export type LoginUserV2ApiArg = {
2774+
/** The user name for login */
2775+
username?: string;
2776+
/** The password for login in clear text */
2777+
password?: string;
2778+
};
2779+
export type LogoutUserV2ApiResponse = unknown;
2780+
export type LogoutUserV2ApiArg = void;
2781+
export type GetUserByNameV2ApiResponse =
2782+
/** status 200 successful operation */ User;
2783+
export type GetUserByNameV2ApiArg = {
2784+
/** The name that needs to be fetched. Use user1 for testing. */
2785+
username: string;
2786+
};
2787+
export type UpdateUserV2ApiResponse = unknown;
2788+
export type UpdateUserV2ApiArg = {
2789+
/** name that need to be deleted */
2790+
username: string;
2791+
/** Update an existent user in the store */
2792+
user: User;
2793+
};
2794+
export type DeleteUserV2ApiResponse = unknown;
2795+
export type DeleteUserV2ApiArg = {
2796+
/** The name that needs to be deleted */
2797+
username: string;
2798+
};
2799+
export type Category = {
2800+
id?: number | undefined;
2801+
name?: string | undefined;
2802+
};
2803+
export type Tag = {
2804+
id?: number | undefined;
2805+
name?: string | undefined;
2806+
};
2807+
export type Pet = {
2808+
id?: number | undefined;
2809+
name: string;
2810+
category?: Category | undefined;
2811+
photoUrls: string[];
2812+
tags?: Tag[] | undefined;
2813+
/** pet status in the store */
2814+
status?: ("available" | "pending" | "sold") | undefined;
2815+
};
2816+
export type ApiResponse = {
2817+
code?: number | undefined;
2818+
type?: string | undefined;
2819+
message?: string | undefined;
2820+
};
2821+
export type Order = {
2822+
id?: number | undefined;
2823+
petId?: number | undefined;
2824+
quantity?: number | undefined;
2825+
shipDate?: string | undefined;
2826+
/** Order Status */
2827+
status?: ("placed" | "approved" | "delivered") | undefined;
2828+
complete?: boolean | undefined;
2829+
};
2830+
export type User = {
2831+
id?: number | undefined;
2832+
username?: string | undefined;
2833+
firstName?: string | undefined;
2834+
lastName?: string | undefined;
2835+
email?: string | undefined;
2836+
password?: string | undefined;
2837+
phone?: string | undefined;
2838+
/** User Status */
2839+
userStatus?: number | undefined;
2840+
};
2841+
"
2842+
`;
2843+
25272844
exports[`query parameters > parameters overridden in swagger should also be overridden in the code 1`] = `
25282845
"import { api } from "./fixtures/emptyApi";
25292846
const injectedRtkApi = api.injectEndpoints({

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,18 @@ test('duplicate parameter names must be prefixed with a path or query prefix', a
423423
expect(api).toMatchSnapshot();
424424
});
425425

426+
test('operation suffixes are applied', async () => {
427+
const api = await generateEndpoints({
428+
unionUndefined: true,
429+
apiFile: './fixtures/emptyApi.ts',
430+
schemaFile: resolve(__dirname, 'fixtures/petstore.json'),
431+
operationNameSuffix: 'V2',
432+
});
433+
434+
expect(api).toContain('AddPetV2');
435+
expect(api).toMatchSnapshot();
436+
});
437+
426438
test('apiImport builds correct `import` statement', async () => {
427439
const api = await generateEndpoints({
428440
unionUndefined: true,

0 commit comments

Comments
 (0)