diff --git a/packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap b/packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap index a88a4786d1..6fd8be8845 100644 --- a/packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap +++ b/packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap @@ -1,29 +1,38 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html 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({ + getHealthcheck: build.query< + GetHealthcheckApiResponse, + GetHealthcheckApiArg + >({ query: () => ({ url: \`/healthcheck\` }), }), updatePet: build.mutation({ - query: (queryArg) => ({ url: \`/pet\`, method: 'PUT', body: queryArg.pet }), + query: (queryArg) => ({ url: \`/pet\`, method: "PUT", body: queryArg.pet }), }), addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), - findPetsByStatus: build.query({ + findPetsByStatus: build.query< + FindPetsByStatusApiResponse, + FindPetsByStatusApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByStatus\`, params: { status: queryArg.status }, }), }), - findPetsByTags: build.query({ + findPetsByTags: build.query< + FindPetsByTagsApiResponse, + FindPetsByTagsApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByTags\`, params: { tags: queryArg.tags }, @@ -32,24 +41,27 @@ const injectedRtkApi = api.injectEndpoints({ getPetById: build.query({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }), }), - updatePetWithForm: build.mutation({ + 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({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, - method: 'DELETE', + method: "DELETE", headers: { api_key: queryArg.apiKey }, }), }), uploadFile: build.mutation({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}/uploadImage\`, - method: 'POST', + method: "POST", body: queryArg.body, params: { additionalMetadata: queryArg.additionalMetadata }, }), @@ -60,7 +72,7 @@ const injectedRtkApi = api.injectEndpoints({ placeOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order\`, - method: 'POST', + method: "POST", body: queryArg.order, }), }), @@ -70,20 +82,23 @@ const injectedRtkApi = api.injectEndpoints({ deleteOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\`, - method: 'DELETE', + method: "DELETE", }), }), createUser: build.mutation({ query: (queryArg) => ({ url: \`/user\`, - method: 'POST', + method: "POST", body: queryArg.user, }), }), - createUsersWithListInput: build.mutation({ + createUsersWithListInput: build.mutation< + CreateUsersWithListInputApiResponse, + CreateUsersWithListInputApiArg + >({ query: (queryArg) => ({ url: \`/user/createWithList\`, - method: 'POST', + method: "POST", body: queryArg.body, }), }), @@ -102,14 +117,14 @@ const injectedRtkApi = api.injectEndpoints({ updateUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'PUT', + method: "PUT", body: queryArg.user, }), }), deleteUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'DELETE', + method: "DELETE", }), }), }), @@ -130,12 +145,14 @@ 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[]; @@ -160,7 +177,8 @@ 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; @@ -172,11 +190,13 @@ 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; @@ -191,11 +211,13 @@ 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; @@ -204,7 +226,8 @@ 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; @@ -235,7 +258,7 @@ export type Pet = { category?: Category | undefined; photoUrls: string[]; tags?: Tag[] | undefined; - status?: ('available' | 'pending' | 'sold') | undefined; + status?: ("available" | "pending" | "sold") | undefined; }; export type ApiResponse = { code?: number | undefined; @@ -247,7 +270,7 @@ export type Order = { petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; - status?: ('placed' | 'approved' | 'delivered') | undefined; + status?: ("placed" | "approved" | "delivered") | undefined; complete?: boolean | undefined; }; export type User = { @@ -264,19 +287,25 @@ export type User = { `; exports[`duplicate parameter names must be prefixed with a path or query prefix 1`] = ` -import { api } from './fixtures/emptyApi'; +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ - patchApiV1ListByItemId: build.mutation({ + 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", }), }), - patchApiV2BySomeName: build.mutation({ + patchApiV2BySomeName: build.mutation< + PatchApiV2BySomeNameApiResponse, + PatchApiV2BySomeNameApiArg + >({ query: (queryArg) => ({ url: \`/api/v2/\${queryArg.pathSomeName}\`, - method: 'PATCH', + method: "PATCH", params: { some_name: queryArg.querySomeName }, }), }), @@ -284,11 +313,13 @@ const injectedRtkApi = api.injectEndpoints({ overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -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; }; -export type PatchApiV2BySomeNameApiResponse = /** status 200 A successful response. */ string; +export type PatchApiV2BySomeNameApiResponse = + /** status 200 A successful response. */ string; export type PatchApiV2BySomeNameApiArg = { pathSomeName: string; querySomeName: string; @@ -296,14 +327,14 @@ export type PatchApiV2BySomeNameApiArg = { `; -exports[`endpoint filtering: should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder 1`] = ` -import { api } from './fixtures/emptyApi'; +exports[`endpoint filtering > should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder 1`] = ` +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ placeOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order\`, - method: 'POST', + method: "POST", body: queryArg.order, }), }), @@ -313,7 +344,7 @@ const injectedRtkApi = api.injectEndpoints({ deleteOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\`, - method: 'DELETE', + method: "DELETE", }), }), loginUser: build.query({ @@ -326,11 +357,13 @@ const injectedRtkApi = api.injectEndpoints({ overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -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; @@ -340,7 +373,8 @@ 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; @@ -352,20 +386,20 @@ export type Order = { petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; - status?: ('placed' | 'approved' | 'delivered') | undefined; + status?: ("placed" | "approved" | "delivered") | undefined; complete?: boolean | undefined; }; `; -exports[`endpoint overrides: loginUser should be a mutation 1`] = ` -import { api } from './fixtures/emptyApi'; +exports[`endpoint overrides > loginUser should be a mutation 1`] = ` +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ loginUser: build.mutation({ query: (queryArg) => ({ url: \`/user/login\`, - method: 'GET', + method: "GET", params: { username: queryArg.username, password: queryArg.password }, }), }), @@ -373,7 +407,8 @@ const injectedRtkApi = api.injectEndpoints({ overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -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; @@ -384,20 +419,20 @@ export type LoginUserApiArg = { `; exports[`falls back to the \`title\` parameter for the body parameter name when no other name is available 1`] = ` -import { api } from 'fixtures/emptyApi'; +import { api } from "fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ postV1Export: build.mutation({ query: (queryArg) => ({ url: \`/v1/export\`, - method: 'POST', + method: "POST", body: queryArg.exportedEntityIds, }), }), postV1Import: build.mutation({ query: (queryArg) => ({ url: \`/v1/import\`, - method: 'POST', + method: "POST", body: queryArg.rawData, }), }), @@ -417,40 +452,14 @@ export type IdList = number[]; `; -exports[`hooks generation uses overrides: should generate an \`useLoginMutation\` mutation hook 1`] = ` -import { api } from './fixtures/emptyApi'; -const injectedRtkApi = api.injectEndpoints({ - endpoints: (build) => ({ - loginUser: build.mutation({ - query: (queryArg) => ({ - url: \`/user/login\`, - method: 'GET', - params: { username: queryArg.username, password: queryArg.password }, - }), - }), - }), - overrideExisting: false, -}); -export { injectedRtkApi as enhancedApi }; -export type LoginUserApiResponse = /** status 200 successful operation */ string; -export type LoginUserApiArg = { - /** The user name for login */ - username?: string; - /** The password for login in clear text */ - password?: string; -}; -export const { useLoginUserMutation } = injectedRtkApi; - -`; - -exports[`hooks generation: should generate an \`useGetPetByIdQuery\` query hook and an \`useAddPetMutation\` mutation hook 1`] = ` -import { api } from './fixtures/emptyApi'; +exports[`hooks generation > should generate an \`useGetPetByIdQuery\` query hook and an \`useAddPetMutation\` mutation hook 1`] = ` +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), @@ -485,14 +494,41 @@ export type Pet = { category?: Category | undefined; photoUrls: string[]; tags?: Tag[] | undefined; - status?: ('available' | 'pending' | 'sold') | undefined; + status?: ("available" | "pending" | "sold") | undefined; }; export const { useAddPetMutation, useGetPetByIdQuery } = injectedRtkApi; `; -exports[`openapi spec readOnly / writeOnly are merged 1`] = ` -import { api } from './fixtures/emptyApi'; +exports[`hooks generation uses overrides > should generate an \`useLoginMutation\` mutation hook 1`] = ` +import { api } from "./fixtures/emptyApi"; +const injectedRtkApi = api.injectEndpoints({ + endpoints: (build) => ({ + loginUser: build.mutation({ + query: (queryArg) => ({ + url: \`/user/login\`, + method: "GET", + params: { username: queryArg.username, password: queryArg.password }, + }), + }), + }), + overrideExisting: false, +}); +export { injectedRtkApi as enhancedApi }; +export type LoginUserApiResponse = + /** status 200 successful operation */ string; +export type LoginUserApiArg = { + /** The user name for login */ + username?: string; + /** The password for login in clear text */ + password?: string; +}; +export const { useLoginUserMutation } = injectedRtkApi; + +`; + +exports[`openapi spec > readOnly / writeOnly are merged 1`] = ` +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ getExample: build.query({ @@ -501,7 +537,7 @@ const injectedRtkApi = api.injectEndpoints({ setExample: build.mutation({ query: (queryArg) => ({ url: \`/example\`, - method: 'POST', + method: "POST", body: queryArg.exampleSchema, }), }), @@ -523,8 +559,8 @@ export type ExampleSchema = { `; -exports[`openapi spec readOnly / writeOnly are respected 1`] = ` -import { api } from './fixtures/emptyApi'; +exports[`openapi spec > readOnly / writeOnly are respected 1`] = ` +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ getExample: build.query({ @@ -533,7 +569,7 @@ const injectedRtkApi = api.injectEndpoints({ setExample: build.mutation({ query: (queryArg) => ({ url: \`/example\`, - method: 'POST', + method: "POST", body: queryArg.exampleSchema, }), }), @@ -562,19 +598,25 @@ export type ExampleSchemaWrite = { `; 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({ + 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", }), }), - patchApiV2BySomeName: build.mutation({ + patchApiV2BySomeName: build.mutation< + PatchApiV2BySomeNameApiResponse, + PatchApiV2BySomeNameApiArg + >({ query: (queryArg) => ({ url: \`/api/v2/\${queryArg.pathSomeName}\`, - method: 'PATCH', + method: "PATCH", params: { some_name: queryArg.querySomeName }, }), }), @@ -582,11 +624,13 @@ const injectedRtkApi = api.injectEndpoints({ overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -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; }; -export type PatchApiV2BySomeNameApiResponse = /** status 200 A successful response. */ string; +export type PatchApiV2BySomeNameApiResponse = + /** status 200 A successful response. */ string; export type PatchApiV2BySomeNameApiArg = { pathSomeName: string; querySomeName: string; @@ -595,13 +639,13 @@ export type PatchApiV2BySomeNameApiArg = { `; exports[`supports granular hooks generation that includes all query types 1`] = ` -import { api } from './fixtures/emptyApi'; +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), @@ -636,20 +680,21 @@ export type Pet = { category?: Category; photoUrls: string[]; tags?: Tag[]; - status?: 'available' | 'pending' | 'sold'; + status?: "available" | "pending" | "sold"; }; -export const { useAddPetMutation, useGetPetByIdQuery, useLazyGetPetByIdQuery } = injectedRtkApi; +export const { useAddPetMutation, useGetPetByIdQuery, useLazyGetPetByIdQuery } = + injectedRtkApi; `; exports[`supports granular hooks generation with only lazy queries 1`] = ` -import { api } from './fixtures/emptyApi'; +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), @@ -684,20 +729,20 @@ export type Pet = { category?: Category; photoUrls: string[]; tags?: Tag[]; - status?: 'available' | 'pending' | 'sold'; + status?: "available" | "pending" | "sold"; }; export const { useLazyGetPetByIdQuery } = injectedRtkApi; `; exports[`supports granular hooks generation with only mutations 1`] = ` -import { api } from './fixtures/emptyApi'; +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), @@ -732,20 +777,20 @@ export type Pet = { category?: Category; photoUrls: string[]; tags?: Tag[]; - status?: 'available' | 'pending' | 'sold'; + status?: "available" | "pending" | "sold"; }; export const { useAddPetMutation } = injectedRtkApi; `; exports[`supports granular hooks generation with only queries 1`] = ` -import { api } from './fixtures/emptyApi'; +import { api } from "./fixtures/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), }), @@ -780,43 +825,49 @@ export type Pet = { category?: Category; photoUrls: string[]; tags?: Tag[]; - status?: 'available' | 'pending' | 'sold'; + status?: "available" | "pending" | "sold"; }; export const { useGetPetByIdQuery } = injectedRtkApi; `; -exports[`tests from issues issue #2002: should be able to generate proper intersection types 1`] = ` -import { api } from './tmp/emptyApi'; +exports[`tests from issues > issue #2002: should be able to generate proper intersection types 1`] = ` +import { api } from "./tmp/emptyApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ - getApiV1Animals: build.query({ + getApiV1Animals: build.query< + GetApiV1AnimalsApiResponse, + GetApiV1AnimalsApiArg + >({ query: (queryArg) => ({ url: \`/api/v1/animals\`, - params: { type: queryArg['type'] }, + params: { type: queryArg["type"] }, }), }), }), overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -export type GetApiV1AnimalsApiResponse = /** status 200 Success */ (Dog | Cat)[]; +export type GetApiV1AnimalsApiResponse = /** status 200 Success */ ( + | Dog + | Cat +)[]; export type GetApiV1AnimalsApiArg = { type?: AnimalType; }; -export type AnimalType = 'All' | 'Cats' | 'Dogs'; +export type AnimalType = "All" | "Cats" | "Dogs"; export type AnimalBase = { type: AnimalType; id?: number; name?: string | null; }; export type Dog = { - type: 'Dog'; + type: "Dog"; } & AnimalBase & { dogUniqueProp?: string | null; }; export type Cat = { - type: 'Cat'; + type: "Cat"; } & AnimalBase & { catUniqueProp?: string | null; }; @@ -824,9 +875,9 @@ export const { useGetApiV1AnimalsQuery } = injectedRtkApi; `; -exports[`yaml parsing should be able to use read a yaml file 1`] = ` -import { api } from './tmp/emptyApi'; -export const addTagTypes = ['pet', 'store', 'user'] as const; +exports[`yaml parsing > should be able to use read a yaml file 1`] = ` +import { api } from "./tmp/emptyApi"; +export const addTagTypes = ["pet", "store", "user"] as const; const injectedRtkApi = api .enhanceEndpoints({ addTagTypes, @@ -836,130 +887,144 @@ const injectedRtkApi = api updatePet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'PUT', + method: "PUT", body: queryArg.pet, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), - findPetsByStatus: build.query({ + findPetsByStatus: build.query< + FindPetsByStatusApiResponse, + FindPetsByStatusApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByStatus\`, params: { status: queryArg.status }, }), - providesTags: ['pet'], + providesTags: ["pet"], }), - findPetsByTags: build.query({ + findPetsByTags: build.query< + FindPetsByTagsApiResponse, + FindPetsByTagsApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByTags\`, params: { tags: queryArg.tags }, }), - providesTags: ['pet'], + providesTags: ["pet"], }), getPetById: build.query({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }), - providesTags: ['pet'], + providesTags: ["pet"], }), - updatePetWithForm: build.mutation({ + updatePetWithForm: build.mutation< + UpdatePetWithFormApiResponse, + UpdatePetWithFormApiArg + >({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, - method: 'POST', + method: "POST", params: { name: queryArg.name, status: queryArg.status }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), deletePet: build.mutation({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, - method: 'DELETE', + method: "DELETE", headers: { api_key: queryArg.apiKey }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), uploadFile: build.mutation({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}/uploadImage\`, - method: 'POST', + method: "POST", body: queryArg.body, params: { additionalMetadata: queryArg.additionalMetadata }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), getInventory: build.query({ query: () => ({ url: \`/store/inventory\` }), - providesTags: ['store'], + providesTags: ["store"], }), placeOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order\`, - method: 'POST', + method: "POST", body: queryArg.order, }), - invalidatesTags: ['store'], + invalidatesTags: ["store"], }), getOrderById: build.query({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\` }), - providesTags: ['store'], + providesTags: ["store"], }), deleteOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\`, - method: 'DELETE', + method: "DELETE", }), - invalidatesTags: ['store'], + invalidatesTags: ["store"], }), createUser: build.mutation({ query: (queryArg) => ({ url: \`/user\`, - method: 'POST', + method: "POST", body: queryArg.user, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), - createUsersWithListInput: build.mutation({ + createUsersWithListInput: build.mutation< + CreateUsersWithListInputApiResponse, + CreateUsersWithListInputApiArg + >({ query: (queryArg) => ({ url: \`/user/createWithList\`, - method: 'POST', + method: "POST", body: queryArg.body, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), loginUser: build.query({ query: (queryArg) => ({ url: \`/user/login\`, params: { username: queryArg.username, password: queryArg.password }, }), - providesTags: ['user'], + providesTags: ["user"], }), logoutUser: build.query({ query: () => ({ url: \`/user/logout\` }), - providesTags: ['user'], - }), - getUserByName: build.query({ - query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }), - providesTags: ['user'], - }), + providesTags: ["user"], + }), + getUserByName: build.query( + { + query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }), + providesTags: ["user"], + }, + ), updateUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'PUT', + method: "PUT", body: queryArg.user, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), deleteUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'DELETE', + method: "DELETE", }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), }), overrideExisting: false, @@ -975,12 +1040,14 @@ 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[]; @@ -1005,7 +1072,8 @@ 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; @@ -1017,11 +1085,13 @@ 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; @@ -1036,11 +1106,13 @@ 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; @@ -1049,7 +1121,8 @@ 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; @@ -1080,7 +1153,7 @@ export type Pet = { category?: Category | undefined; photoUrls: string[]; tags?: Tag[] | undefined; - status?: ('available' | 'pending' | 'sold') | undefined; + status?: ("available" | "pending" | "sold") | undefined; }; export type ApiResponse = { code?: number | undefined; @@ -1092,7 +1165,7 @@ export type Order = { petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; - status?: ('placed' | 'approved' | 'delivered') | undefined; + status?: ("placed" | "approved" | "delivered") | undefined; complete?: boolean | undefined; }; export type User = { @@ -1129,47 +1202,51 @@ export const { `; -exports[`yaml parsing should generate params with non quoted keys if they don't contain special characters 1`] = ` -import { api } from './tmp/emptyApi'; -export const addTagTypes = ['StructureDefinition'] as const; +exports[`yaml parsing > should generate params with non quoted keys if they don't contain special characters 1`] = ` +import { api } from "./tmp/emptyApi"; +export const addTagTypes = ["StructureDefinition"] as const; const injectedRtkApi = api .enhanceEndpoints({ addTagTypes, }) .injectEndpoints({ endpoints: (build) => ({ - getStructureDefinition: build.query({ + getStructureDefinition: build.query< + GetStructureDefinitionApiResponse, + GetStructureDefinitionApiArg + >({ query: (queryArg) => ({ url: \`/StructureDefinition\`, params: { foo: queryArg.foo, _foo: queryArg._foo, - '-bar-bar': queryArg['-bar-bar'], + "-bar-bar": queryArg["-bar-bar"], _bar_bar: queryArg._bar_bar, - 'foo:bar-foo.bar/foo': queryArg['foo:bar-foo.bar/foo'], + "foo:bar-foo.bar/foo": queryArg["foo:bar-foo.bar/foo"], foo_bar: queryArg.fooBar, namingConflict: queryArg.namingConflict, naming_conflict: queryArg.naming_conflict, }, }), - providesTags: ['StructureDefinition'], + providesTags: ["StructureDefinition"], }), }), overrideExisting: false, }); export { injectedRtkApi as enhancedApi }; -export type GetStructureDefinitionApiResponse = /** status 200 Success */ FhirJsonResource; +export type GetStructureDefinitionApiResponse = + /** status 200 Success */ FhirJsonResource; export type GetStructureDefinitionApiArg = { /** Some description */ foo?: any; /** Some description */ _foo?: any; /** Some description */ - '-bar-bar'?: any; + "-bar-bar"?: any; /** Some description */ _bar_bar?: any; /** Some description */ - 'foo:bar-foo.bar/foo'?: any; + "foo:bar-foo.bar/foo"?: any; /** Some description */ fooBar?: any; /** Some description */ @@ -1182,9 +1259,9 @@ export const { useGetStructureDefinitionQuery } = injectedRtkApi; `; -exports[`yaml parsing should parse a yaml schema from a URL 1`] = ` -import { api } from './tmp/emptyApi'; -export const addTagTypes = ['pet', 'store', 'user'] as const; +exports[`yaml parsing > should parse a yaml schema from a URL 1`] = ` +import { api } from "./tmp/emptyApi"; +export const addTagTypes = ["pet", "store", "user"] as const; const injectedRtkApi = api .enhanceEndpoints({ addTagTypes, @@ -1194,130 +1271,144 @@ const injectedRtkApi = api updatePet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'PUT', + method: "PUT", body: queryArg.pet, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), addPet: build.mutation({ query: (queryArg) => ({ url: \`/pet\`, - method: 'POST', + method: "POST", body: queryArg.pet, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), - findPetsByStatus: build.query({ + findPetsByStatus: build.query< + FindPetsByStatusApiResponse, + FindPetsByStatusApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByStatus\`, params: { status: queryArg.status }, }), - providesTags: ['pet'], + providesTags: ["pet"], }), - findPetsByTags: build.query({ + findPetsByTags: build.query< + FindPetsByTagsApiResponse, + FindPetsByTagsApiArg + >({ query: (queryArg) => ({ url: \`/pet/findByTags\`, params: { tags: queryArg.tags }, }), - providesTags: ['pet'], + providesTags: ["pet"], }), getPetById: build.query({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\` }), - providesTags: ['pet'], + providesTags: ["pet"], }), - updatePetWithForm: build.mutation({ + updatePetWithForm: build.mutation< + UpdatePetWithFormApiResponse, + UpdatePetWithFormApiArg + >({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, - method: 'POST', + method: "POST", params: { name: queryArg.name, status: queryArg.status }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), deletePet: build.mutation({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}\`, - method: 'DELETE', + method: "DELETE", headers: { api_key: queryArg.apiKey }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), uploadFile: build.mutation({ query: (queryArg) => ({ url: \`/pet/\${queryArg.petId}/uploadImage\`, - method: 'POST', + method: "POST", body: queryArg.body, params: { additionalMetadata: queryArg.additionalMetadata }, }), - invalidatesTags: ['pet'], + invalidatesTags: ["pet"], }), getInventory: build.query({ query: () => ({ url: \`/store/inventory\` }), - providesTags: ['store'], + providesTags: ["store"], }), placeOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order\`, - method: 'POST', + method: "POST", body: queryArg.order, }), - invalidatesTags: ['store'], + invalidatesTags: ["store"], }), getOrderById: build.query({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\` }), - providesTags: ['store'], + providesTags: ["store"], }), deleteOrder: build.mutation({ query: (queryArg) => ({ url: \`/store/order/\${queryArg.orderId}\`, - method: 'DELETE', + method: "DELETE", }), - invalidatesTags: ['store'], + invalidatesTags: ["store"], }), createUser: build.mutation({ query: (queryArg) => ({ url: \`/user\`, - method: 'POST', + method: "POST", body: queryArg.user, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), - createUsersWithListInput: build.mutation({ + createUsersWithListInput: build.mutation< + CreateUsersWithListInputApiResponse, + CreateUsersWithListInputApiArg + >({ query: (queryArg) => ({ url: \`/user/createWithList\`, - method: 'POST', + method: "POST", body: queryArg.body, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), loginUser: build.query({ query: (queryArg) => ({ url: \`/user/login\`, params: { username: queryArg.username, password: queryArg.password }, }), - providesTags: ['user'], + providesTags: ["user"], }), logoutUser: build.query({ query: () => ({ url: \`/user/logout\` }), - providesTags: ['user'], - }), - getUserByName: build.query({ - query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }), - providesTags: ['user'], - }), + providesTags: ["user"], + }), + getUserByName: build.query( + { + query: (queryArg) => ({ url: \`/user/\${queryArg.username}\` }), + providesTags: ["user"], + }, + ), updateUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'PUT', + method: "PUT", body: queryArg.user, }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), deleteUser: build.mutation({ query: (queryArg) => ({ url: \`/user/\${queryArg.username}\`, - method: 'DELETE', + method: "DELETE", }), - invalidatesTags: ['user'], + invalidatesTags: ["user"], }), }), overrideExisting: false, @@ -1333,12 +1424,14 @@ 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[]; @@ -1363,7 +1456,8 @@ 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; @@ -1375,11 +1469,13 @@ 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; @@ -1394,11 +1490,13 @@ 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; @@ -1407,7 +1505,8 @@ 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; @@ -1438,7 +1537,7 @@ export type Pet = { category?: Category | undefined; photoUrls: string[]; tags?: Tag[] | undefined; - status?: ('available' | 'pending' | 'sold') | undefined; + status?: ("available" | "pending" | "sold") | undefined; }; export type ApiResponse = { code?: number | undefined; @@ -1450,7 +1549,7 @@ export type Order = { petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; - status?: ('placed' | 'approved' | 'delivered') | undefined; + status?: ("placed" | "approved" | "delivered") | undefined; complete?: boolean | undefined; }; export type User = {