Skip to content

Commit

Permalink
add serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 1, 2021
1 parent fffec14 commit 3278020
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 83 deletions.
132 changes: 50 additions & 82 deletions test/__snapshots__/generateEndpoints.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calling without \`outputFile\` returns the generated api 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
getHealthcheck: build.query<
GetHealthcheckApiResponse,
GetHealthcheckApiArg
>({
getHealthcheck: build.query<GetHealthcheckApiResponse, GetHealthcheckApiArg>({
query: () => ({ url: \`/healthcheck\` }),
}),
updatePet: build.mutation<UpdatePetApiResponse, UpdatePetApiArg>({
query: (queryArg) => ({ url: \`/pet\`, method: "PUT", body: queryArg.pet }),
query: (queryArg) => ({ url: \`/pet\`, method: 'PUT', body: queryArg.pet }),
}),
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
query: (queryArg) => ({
url: \`/pet\`,
method: "POST",
method: 'POST',
body: queryArg.pet,
}),
}),
findPetsByStatus: build.query<
FindPetsByStatusApiResponse,
FindPetsByStatusApiArg
>({
findPetsByStatus: build.query<FindPetsByStatusApiResponse, FindPetsByStatusApiArg>({
query: (queryArg) => ({
url: \`/pet/findByStatus\`,
params: { status: queryArg.status },
}),
}),
findPetsByTags: build.query<
FindPetsByTagsApiResponse,
FindPetsByTagsApiArg
>({
findPetsByTags: build.query<FindPetsByTagsApiResponse, FindPetsByTagsApiArg>({
query: (queryArg) => ({
url: \`/pet/findByTags\`,
params: { tags: queryArg.tags },
Expand All @@ -41,27 +32,24 @@ const injectedRtkApi = api.injectEndpoints({
getPetById: build.query<GetPetByIdApiResponse, GetPetByIdApiArg>({
query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }),
}),
updatePetWithForm: build.mutation<
UpdatePetWithFormApiResponse,
UpdatePetWithFormApiArg
>({
updatePetWithForm: build.mutation<UpdatePetWithFormApiResponse, UpdatePetWithFormApiArg>({
query: (queryArg) => ({
url: \`/pet/\${queryArg.petId}\`,
method: "POST",
method: 'POST',
params: { name: queryArg.name, status: queryArg.status },
}),
}),
deletePet: build.mutation<DeletePetApiResponse, DeletePetApiArg>({
query: (queryArg) => ({
url: \`/pet/\${queryArg.petId}\`,
method: "DELETE",
method: 'DELETE',
headers: { api_key: queryArg.apiKey },
}),
}),
uploadFile: build.mutation<UploadFileApiResponse, UploadFileApiArg>({
query: (queryArg) => ({
url: \`/pet/\${queryArg.petId}/uploadImage\`,
method: "POST",
method: 'POST',
body: queryArg.body,
params: { additionalMetadata: queryArg.additionalMetadata },
}),
Expand All @@ -72,7 +60,7 @@ const injectedRtkApi = api.injectEndpoints({
placeOrder: build.mutation<PlaceOrderApiResponse, PlaceOrderApiArg>({
query: (queryArg) => ({
url: \`/store/order\`,
method: "POST",
method: 'POST',
body: queryArg.order,
}),
}),
Expand All @@ -82,23 +70,20 @@ const injectedRtkApi = api.injectEndpoints({
deleteOrder: build.mutation<DeleteOrderApiResponse, DeleteOrderApiArg>({
query: (queryArg) => ({
url: \`/store/order/\${queryArg.orderId}\`,
method: "DELETE",
method: 'DELETE',
}),
}),
createUser: build.mutation<CreateUserApiResponse, CreateUserApiArg>({
query: (queryArg) => ({
url: \`/user\`,
method: "POST",
method: 'POST',
body: queryArg.user,
}),
}),
createUsersWithListInput: build.mutation<
CreateUsersWithListInputApiResponse,
CreateUsersWithListInputApiArg
>({
createUsersWithListInput: build.mutation<CreateUsersWithListInputApiResponse, CreateUsersWithListInputApiArg>({
query: (queryArg) => ({
url: \`/user/createWithList\`,
method: "POST",
method: 'POST',
body: queryArg.body,
}),
}),
Expand All @@ -117,14 +102,14 @@ const injectedRtkApi = api.injectEndpoints({
updateUser: build.mutation<UpdateUserApiResponse, UpdateUserApiArg>({
query: (queryArg) => ({
url: \`/user/\${queryArg.username}\`,
method: "PUT",
method: 'PUT',
body: queryArg.user,
}),
}),
deleteUser: build.mutation<DeleteUserApiResponse, DeleteUserApiArg>({
query: (queryArg) => ({
url: \`/user/\${queryArg.username}\`,
method: "DELETE",
method: 'DELETE',
}),
}),
}),
Expand All @@ -145,14 +130,12 @@ export type AddPetApiArg = {
/** Create a new pet in the store */
pet: Pet;
};
export type FindPetsByStatusApiResponse =
/** status 200 successful operation */ Pet[];
export type FindPetsByStatusApiResponse = /** status 200 successful operation */ Pet[];
export type FindPetsByStatusApiArg = {
/** Status values that need to be considered for filter */
status?: "available" | "pending" | "sold";
status?: 'available' | 'pending' | 'sold';
};
export type FindPetsByTagsApiResponse =
/** status 200 successful operation */ Pet[];
export type FindPetsByTagsApiResponse = /** status 200 successful operation */ Pet[];
export type FindPetsByTagsApiArg = {
/** Tags to filter by */
tags?: string[];
Expand All @@ -177,8 +160,7 @@ export type DeletePetApiArg = {
/** Pet id to delete */
petId: number;
};
export type UploadFileApiResponse =
/** status 200 successful operation */ ApiResponse;
export type UploadFileApiResponse = /** status 200 successful operation */ ApiResponse;
export type UploadFileApiArg = {
/** ID of pet to update */
petId: number;
Expand All @@ -190,13 +172,11 @@ export type GetInventoryApiResponse = /** status 200 successful operation */ {
[key: string]: number;
};
export type GetInventoryApiArg = void;
export type PlaceOrderApiResponse =
/** status 200 successful operation */ Order;
export type PlaceOrderApiResponse = /** status 200 successful operation */ Order;
export type PlaceOrderApiArg = {
order: Order;
};
export type GetOrderByIdApiResponse =
/** status 200 successful operation */ Order;
export type GetOrderByIdApiResponse = /** status 200 successful operation */ Order;
export type GetOrderByIdApiArg = {
/** ID of order that needs to be fetched */
orderId: number;
Expand All @@ -211,13 +191,11 @@ export type CreateUserApiArg = {
/** Created user object */
user: User;
};
export type CreateUsersWithListInputApiResponse =
/** status 200 Successful operation */ User;
export type CreateUsersWithListInputApiResponse = /** status 200 Successful operation */ User;
export type CreateUsersWithListInputApiArg = {
body: User[];
};
export type LoginUserApiResponse =
/** status 200 successful operation */ string;
export type LoginUserApiResponse = /** status 200 successful operation */ string;
export type LoginUserApiArg = {
/** The user name for login */
username?: string;
Expand All @@ -226,8 +204,7 @@ export type LoginUserApiArg = {
};
export type LogoutUserApiResponse = unknown;
export type LogoutUserApiArg = void;
export type GetUserByNameApiResponse =
/** status 200 successful operation */ User;
export type GetUserByNameApiResponse = /** status 200 successful operation */ User;
export type GetUserByNameApiArg = {
/** The name that needs to be fetched. Use user1 for testing. */
username: string;
Expand Down Expand Up @@ -258,7 +235,7 @@ export type Pet = {
category?: Category;
photoUrls: string[];
tags?: Tag[];
status?: "available" | "pending" | "sold";
status?: 'available' | 'pending' | 'sold';
};
export type ApiResponse = {
code?: number;
Expand All @@ -270,7 +247,7 @@ export type Order = {
petId?: number;
quantity?: number;
shipDate?: string;
status?: "placed" | "approved" | "delivered";
status?: 'placed' | 'approved' | 'delivered';
complete?: boolean;
};
export type User = {
Expand All @@ -287,13 +264,13 @@ export type User = {
`;
exports[`endpoint filtering: should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
placeOrder: build.mutation<PlaceOrderApiResponse, PlaceOrderApiArg>({
query: (queryArg) => ({
url: \`/store/order\`,
method: "POST",
method: 'POST',
body: queryArg.order,
}),
}),
Expand All @@ -303,7 +280,7 @@ const injectedRtkApi = api.injectEndpoints({
deleteOrder: build.mutation<DeleteOrderApiResponse, DeleteOrderApiArg>({
query: (queryArg) => ({
url: \`/store/order/\${queryArg.orderId}\`,
method: "DELETE",
method: 'DELETE',
}),
}),
loginUser: build.query<LoginUserApiResponse, LoginUserApiArg>({
Expand All @@ -316,13 +293,11 @@ const injectedRtkApi = api.injectEndpoints({
overrideExisting: false,
});
export { injectedRtkApi as api };
export type PlaceOrderApiResponse =
/** status 200 successful operation */ Order;
export type PlaceOrderApiResponse = /** status 200 successful operation */ Order;
export type PlaceOrderApiArg = {
order: Order;
};
export type GetOrderByIdApiResponse =
/** status 200 successful operation */ Order;
export type GetOrderByIdApiResponse = /** status 200 successful operation */ Order;
export type GetOrderByIdApiArg = {
/** ID of order that needs to be fetched */
orderId: number;
Expand All @@ -332,8 +307,7 @@ export type DeleteOrderApiArg = {
/** ID of the order that needs to be deleted */
orderId: number;
};
export type LoginUserApiResponse =
/** status 200 successful operation */ string;
export type LoginUserApiResponse = /** status 200 successful operation */ string;
export type LoginUserApiArg = {
/** The user name for login */
username?: string;
Expand All @@ -345,29 +319,28 @@ export type Order = {
petId?: number;
quantity?: number;
shipDate?: string;
status?: "placed" | "approved" | "delivered";
status?: 'placed' | 'approved' | 'delivered';
complete?: boolean;
};
`;
exports[`endpoint overrides: loginUser should be a mutation 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
loginUser: build.mutation<LoginUserApiResponse, LoginUserApiArg>({
query: (queryArg) => ({
url: \`/user/login\`,
method: "GET",
method: 'GET',
params: { username: queryArg.username, password: queryArg.password },
}),
}),
}),
overrideExisting: false,
});
export { injectedRtkApi as api };
export type LoginUserApiResponse =
/** status 200 successful operation */ string;
export type LoginUserApiResponse = /** status 200 successful operation */ string;
export type LoginUserApiArg = {
/** The user name for login */
username?: string;
Expand All @@ -378,22 +351,21 @@ export type LoginUserApiArg = {
`;
exports[`hooks generation uses overrides: should generate an \`useLoginMutation\` mutation hook 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
loginUser: build.mutation<LoginUserApiResponse, LoginUserApiArg>({
query: (queryArg) => ({
url: \`/user/login\`,
method: "GET",
method: 'GET',
params: { username: queryArg.username, password: queryArg.password },
}),
}),
}),
overrideExisting: false,
});
export { injectedRtkApi as api };
export type LoginUserApiResponse =
/** status 200 successful operation */ string;
export type LoginUserApiResponse = /** status 200 successful operation */ string;
export type LoginUserApiArg = {
/** The user name for login */
username?: string;
Expand All @@ -405,13 +377,13 @@ export const { useLoginUserMutation } = enhancedApi;
`;
exports[`hooks generation: should generate an \`useGetPetByIdQuery\` query hook and an \`useAddPetMutation\` mutation hook 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
query: (queryArg) => ({
url: \`/pet\`,
method: "POST",
method: 'POST',
body: queryArg.pet,
}),
}),
Expand Down Expand Up @@ -446,33 +418,29 @@ export type Pet = {
category?: Category;
photoUrls: string[];
tags?: Tag[];
status?: "available" | "pending" | "sold";
status?: 'available' | 'pending' | 'sold';
};
export const { useAddPetMutation, useGetPetByIdQuery } = enhancedApi;
`;
exports[`should use brackets in a querystring urls arg, when the arg contains full stops 1`] = `
import { api } from "./fixtures/emptyApi";
import { api } from './fixtures/emptyApi';
const injectedRtkApi = api.injectEndpoints({
endpoints: (build) => ({
patchApiV1ListByItemId: build.mutation<
PatchApiV1ListByItemIdApiResponse,
PatchApiV1ListByItemIdApiArg
>({
patchApiV1ListByItemId: build.mutation<PatchApiV1ListByItemIdApiResponse, PatchApiV1ListByItemIdApiArg>({
query: (queryArg) => ({
url: \`/api/v1/list/\${queryArg["item.id"]}\`,
method: "PATCH",
url: \`/api/v1/list/\${queryArg['item.id']}\`,
method: 'PATCH',
}),
}),
}),
overrideExisting: false,
});
export { injectedRtkApi as api };
export type PatchApiV1ListByItemIdApiResponse =
/** status 200 A successful response. */ string;
export type PatchApiV1ListByItemIdApiResponse = /** status 200 A successful response. */ string;
export type PatchApiV1ListByItemIdApiArg = {
"item.id": string;
'item.id': string;
};
`;
Loading

0 comments on commit 3278020

Please sign in to comment.