🧴
openAPI クライアントライブラリ比較
作成日: 2023-08-17T01:37:00.000Z
最終更新: 2024-08-07T13:14:00.000Z
openapi-typescript
- これは何
- OpenAPI 3 仕様から Node.js のみを使用して(20.x 以降を推奨) TypeScript 型を生成する
- 使い方
- [https://openapi-ts.pages.dev/introduction/](https://openapi-ts.pages.dev/introduction/)
- 生成した型
- デフォルトではオブジェクト型
<details>
<summary>schema.d.ts</summary>
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
export interface paths {
"/pet": {
/**
* Update an existing pet
* @description Update an existing pet by Id
*/
put: operations["updatePet"];
/**
* Add a new pet to the store
* @description Add a new pet to the store
*/
post: operations["addPet"];
};
"/pet/findByStatus": {
/**
* Finds Pets by status
* @description Multiple status values can be provided with comma separated strings
*/
get: operations["findPetsByStatus"];
};
"/pet/findByTags": {
/**
* Finds Pets by tags
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*/
get: operations["findPetsByTags"];
};
"/pet/{petId}": {
/**
* Find pet by ID
* @description Returns a single pet
*/
get: operations["getPetById"];
/** Updates a pet in the store with form data */
post: operations["updatePetWithForm"];
/**
* Deletes a pet
* @description delete a pet
*/
delete: operations["deletePet"];
};
"/pet/{petId}/uploadImage": {
/** uploads an image */
post: operations["uploadFile"];
};
"/store/inventory": {
/**
* Returns pet inventories by status
* @description Returns a map of status codes to quantities
*/
get: operations["getInventory"];
};
"/store/order": {
/**
* Place an order for a pet
* @description Place a new order in the store
*/
post: operations["placeOrder"];
};
"/store/order/{orderId}": {
/**
* Find purchase order by ID
* @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
*/
get: operations["getOrderById"];
/**
* Delete purchase order by ID
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*/
delete: operations["deleteOrder"];
};
"/user": {
/**
* Create user
* @description This can only be done by the logged in user.
*/
post: operations["createUser"];
};
"/user/createWithList": {
/**
* Creates list of users with given input array
* @description Creates list of users with given input array
*/
post: operations["createUsersWithListInput"];
};
"/user/login": {
/** Logs user into the system */
get: operations["loginUser"];
};
"/user/logout": {
/** Logs out current logged in user session */
get: operations["logoutUser"];
};
"/user/{username}": {
/** Get user by user name */
get: operations["getUserByName"];
/**
* Update user
* @description This can only be done by the logged in user.
*/
put: operations["updateUser"];
/**
* Delete user
* @description This can only be done by the logged in user.
*/
delete: operations["deleteUser"];
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
Order: {
/**
* Format: int64
* @example 10
*/
id?: number;
/**
* Format: int64
* @example 198772
*/
petId?: number;
/**
* Format: int32
* @example 7
*/
quantity?: number;
/** Format: date-time */
shipDate?: string;
/**
* @description Order Status
* @example approved
* @enum {string}
*/
status?: "placed" | "approved" | "delivered";
complete?: boolean;
};
Customer: {
/**
* Format: int64
* @example 100000
*/
id?: number;
/** @example fehguy */
username?: string;
address?: components["schemas"]["Address"][];
};
Address: {
/** @example 437 Lytton */
street?: string;
/** @example Palo Alto */
city?: string;
/** @example CA */
state?: string;
/** @example 94301 */
zip?: string;
};
Category: {
/**
* Format: int64
* @example 1
*/
id?: number;
/** @example Dogs */
name?: string;
};
User: {
/**
* Format: int64
* @example 10
*/
id?: number;
/** @example theUser */
username?: string;
/** @example John */
firstName?: string;
/** @example James */
lastName?: string;
/** @example john@email.com */
email?: string;
/** @example 12345 */
password?: string;
/** @example 12345 */
phone?: string;
/**
* Format: int32
* @description User Status
* @example 1
*/
userStatus?: number;
};
Tag: {
/** Format: int64 */
id?: number;
name?: string;
};
Pet: {
/**
* Format: int64
* @example 10
*/
id?: number;
/** @example doggie */
name: string;
category?: components["schemas"]["Category"];
photoUrls: string[];
tags?: components["schemas"]["Tag"][];
/**
* @description pet status in the store
* @enum {string}
*/
status?: "available" | "pending" | "sold";
};
ApiResponse: {
/** Format: int32 */
code?: number;
type?: string;
message?: string;
};
};
responses: never;
parameters: never;
requestBodies: {
/** @description Pet object that needs to be added to the store */
Pet?: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
};
};
/** @description List of user object */
UserArray?: {
content: {
"application/json": components["schemas"]["User"][];
};
};
};
headers: never;
pathItems: never;
}
export type external = Record<string, never>;
export interface operations {
/**
* Update an existing pet
* @description Update an existing pet by Id
*/
updatePet: {
/** @description Update an existent pet in the store */
requestBody: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
"application/x-www-form-urlencoded": components["schemas"]["Pet"];
};
};
responses: {
/** @description Successful operation */
200: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
};
};
/** @description Invalid ID supplied */
400: never;
/** @description Pet not found */
404: never;
/** @description Validation exception */
405: never;
};
};
/**
* Add a new pet to the store
* @description Add a new pet to the store
*/
addPet: {
/** @description Create a new pet in the store */
requestBody: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
"application/x-www-form-urlencoded": components["schemas"]["Pet"];
};
};
responses: {
/** @description Successful operation */
200: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
};
};
/** @description Invalid input */
405: never;
};
};
/**
* Finds Pets by status
* @description Multiple status values can be provided with comma separated strings
*/
findPetsByStatus: {
parameters: {
query?: {
/** @description Status values that need to be considered for filter */
status?: "available" | "pending" | "sold";
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["Pet"][];
"application/xml": components["schemas"]["Pet"][];
};
};
/** @description Invalid status value */
400: never;
};
};
/**
* Finds Pets by tags
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*/
findPetsByTags: {
parameters: {
query?: {
/** @description Tags to filter by */
tags?: string[];
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["Pet"][];
"application/xml": components["schemas"]["Pet"][];
};
};
/** @description Invalid tag value */
400: never;
};
};
/**
* Find pet by ID
* @description Returns a single pet
*/
getPetById: {
parameters: {
path: {
/** @description ID of pet to return */
petId: number;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["Pet"];
"application/xml": components["schemas"]["Pet"];
};
};
/** @description Invalid ID supplied */
400: never;
/** @description Pet not found */
404: never;
};
};
/** Updates a pet in the store with form data */
updatePetWithForm: {
parameters: {
query?: {
/** @description Name of pet that needs to be updated */
name?: string;
/** @description Status of pet that needs to be updated */
status?: string;
};
path: {
/** @description ID of pet that needs to be updated */
petId: number;
};
};
responses: {
/** @description Invalid input */
405: never;
};
};
/**
* Deletes a pet
* @description delete a pet
*/
deletePet: {
parameters: {
header?: {
api_key?: string;
};
path: {
/** @description Pet id to delete */
petId: number;
};
};
responses: {
/** @description Invalid pet value */
400: never;
};
};
/** uploads an image */
uploadFile: {
parameters: {
query?: {
/** @description Additional Metadata */
additionalMetadata?: string;
};
path: {
/** @description ID of pet to update */
petId: number;
};
};
requestBody?: {
content: {
"application/octet-stream": string;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["ApiResponse"];
};
};
};
};
/**
* Returns pet inventories by status
* @description Returns a map of status codes to quantities
*/
getInventory: {
responses: {
/** @description successful operation */
200: {
content: {
"application/json": {
[key: string]: number | undefined;
};
};
};
};
};
/**
* Place an order for a pet
* @description Place a new order in the store
*/
placeOrder: {
requestBody?: {
content: {
"application/json": components["schemas"]["Order"];
"application/xml": components["schemas"]["Order"];
"application/x-www-form-urlencoded": components["schemas"]["Order"];
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["Order"];
};
};
/** @description Invalid input */
405: never;
};
};
/**
* Find purchase order by ID
* @description For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
*/
getOrderById: {
parameters: {
path: {
/** @description ID of order that needs to be fetched */
orderId: number;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["Order"];
"application/xml": components["schemas"]["Order"];
};
};
/** @description Invalid ID supplied */
400: never;
/** @description Order not found */
404: never;
};
};
/**
* Delete purchase order by ID
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*/
deleteOrder: {
parameters: {
path: {
/** @description ID of the order that needs to be deleted */
orderId: number;
};
};
responses: {
/** @description Invalid ID supplied */
400: never;
/** @description Order not found */
404: never;
};
};
/**
* Create user
* @description This can only be done by the logged in user.
*/
createUser: {
/** @description Created user object */
requestBody?: {
content: {
"application/json": components["schemas"]["User"];
"application/xml": components["schemas"]["User"];
"application/x-www-form-urlencoded": components["schemas"]["User"];
};
};
responses: {
/** @description successful operation */
default: {
content: {
"application/json": components["schemas"]["User"];
"application/xml": components["schemas"]["User"];
};
};
};
};
/**
* Creates list of users with given input array
* @description Creates list of users with given input array
*/
createUsersWithListInput: {
requestBody?: {
content: {
"application/json": components["schemas"]["User"][];
};
};
responses: {
/** @description Successful operation */
200: {
content: {
"application/json": components["schemas"]["User"];
"application/xml": components["schemas"]["User"];
};
};
/** @description successful operation */
default: never;
};
};
/** Logs user into the system */
loginUser: {
parameters: {
query?: {
/** @description The user name for login */
username?: string;
/** @description The password for login in clear text */
password?: string;
};
};
responses: {
/** @description successful operation */
200: {
headers: {
/** @description calls per hour allowed by the user */
"X-Rate-Limit"?: number;
/** @description date in UTC when token expires */
"X-Expires-After"?: string;
};
content: {
"application/xml": string;
"application/json": string;
};
};
/** @description Invalid username/password supplied */
400: never;
};
};
/** Logs out current logged in user session */
logoutUser: {
responses: {
/** @description successful operation */
default: never;
};
};
/** Get user by user name */
getUserByName: {
parameters: {
path: {
/** @description The name that needs to be fetched. Use user1 for testing. */
username: string;
};
};
responses: {
/** @description successful operation */
200: {
content: {
"application/json": components["schemas"]["User"];
"application/xml": components["schemas"]["User"];
};
};
/** @description Invalid username supplied */
400: never;
/** @description User not found */
404: never;
};
};
/**
* Update user
* @description This can only be done by the logged in user.
*/
updateUser: {
parameters: {
path: {
/** @description name that need to be deleted */
username: string;
};
};
/** @description Update an existent user in the store */
requestBody?: {
content: {
"application/json": components["schemas"]["User"];
"application/xml": components["schemas"]["User"];
"application/x-www-form-urlencoded": components["schemas"]["User"];
};
};
responses: {
/** @description successful operation */
default: never;
};
};
/**
* Delete user
* @description This can only be done by the logged in user.
*/
deleteUser: {
parameters: {
path: {
/** @description The name that needs to be deleted */
username: string;
};
};
responses: {
/** @description Invalid username supplied */
400: never;
/** @description User not found */
404: never;
};
};
}
</details>
- オブジェクト以外の形で生成は可能か?
- おそらくなさそう
- api fetchコードの作成
- [https://openapi-ts.pages.dev/openapi-fetch/](https://openapi-ts.pages.dev/openapi-fetch/)
- 計量かつシンプルな、openapi-fetchを利用することで、openapi-typescriptで生成した型を元に型安全なAPIリクエストのコードを記述することができる
- 他のこの手のライブラリと比較すると、自動でクライアントコードを生成するわけではないため、自前で実装したい場合には向いていそう
- まとめ
- シンプルなのでとっつきやすい
- 一方でhooksやクライアントコード、モック等の自動生成などはない
- 型定義はオブジェクトなので、参照する時は若干冗長
- リンク
- [https://github.com/drwpow/openapi-typescript](https://github.com/drwpow/openapi-typescript)
orval
- これは何
- 有効な OpenAPI v3 または Swagger v2 仕様から、yaml または json 形式で、適切な型署名 (TypeScript) を持つクライアントを生成できます。🍺
- 使い方
- [https://orval.dev/quick-start](https://orval.dev/quick-start)
- config
- [https://orval.dev/reference/configuration/overview](https://orval.dev/reference/configuration/overview)
- クライアントを指定する([デフォルトはaxios-functions](https://orval.dev/reference/configuration/output#client))
- デフォルトでは、1つのファイルに型生成とAPIリクエストのコードが生成されてしまう
- [mode](https://orval.dev/reference/configuration/output#mode) でsplitを指定することで分けることが可能
- 生成した型
<details>
<summary>swaggerPetstoreOpenAPI30.schemas.ts</summary>
/**
* Generated by orval v6.17.0 🍺
* Do not edit manually.
* Swagger Petstore - OpenAPI 3.0
* This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
_If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
* OpenAPI spec version: 1.0.11
*/
export type LoginUserParams = {
/**
* The user name for login
*/
username?: string;
/**
* The password for login in clear text
*/
password?: string;
};
export type GetInventory200 = {[key: string]: number};
export type UploadFileParams = {
/**
* Additional Metadata
*/
additionalMetadata?: string;
};
export type UpdatePetWithFormParams = {
/**
* Name of pet that needs to be updated
*/
name?: string;
/**
* Status of pet that needs to be updated
*/
status?: string;
};
export type FindPetsByTagsParams = {
/**
* Tags to filter by
*/
tags?: string[];
};
export type FindPetsByStatusStatus = typeof FindPetsByStatusStatus[keyof typeof FindPetsByStatusStatus];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const FindPetsByStatusStatus = {
available: 'available',
pending: 'pending',
sold: 'sold',
} as const;
export type FindPetsByStatusParams = {
/**
* Status values that need to be considered for filter
*/
status?: FindPetsByStatusStatus;
};
/**
* Pet object that needs to be added to the store
*/
export type PetBody = Pet;
export interface ApiResponse {
code?: number;
type?: string;
message?: string;
}
/**
* pet status in the store
*/
export type PetStatus = typeof PetStatus[keyof typeof PetStatus];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const PetStatus = {
available: 'available',
pending: 'pending',
sold: 'sold',
} as const;
export interface Tag {
id?: number;
name?: string;
}
export interface Pet {
id?: number;
name: string;
category?: Category;
photoUrls: string[];
tags?: Tag[];
/** pet status in the store */
status?: PetStatus;
}
export interface User {
id?: number;
username?: string;
firstName?: string;
lastName?: string;
email?: string;
password?: string;
phone?: string;
/** User Status */
userStatus?: number;
}
/**
* List of user object
*/
export type UserArrayBody = User[];
export interface Category {
id?: number;
name?: string;
}
export interface Address {
street?: string;
city?: string;
state?: string;
zip?: string;
}
export interface Customer {
id?: number;
username?: string;
address?: Address[];
}
/**
* Order Status
*/
export type OrderStatus = typeof OrderStatus[keyof typeof OrderStatus];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const OrderStatus = {
placed: 'placed',
approved: 'approved',
delivered: 'delivered',
} as const;
export interface Order {
id?: number;
petId?: number;
quantity?: number;
shipDate?: string;
/** Order Status */
status?: OrderStatus;
complete?: boolean;
}
</details>
<details>
<summary>swaggerPetstoreOpenAPI30.ts(自動で生成されるクライアントコード)</summary>
/**
* Generated by orval v6.17.0 🍺
* Do not edit manually.
* Swagger Petstore - OpenAPI 3.0
* This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
_If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
* OpenAPI spec version: 1.0.11
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse,
AxiosError
} from 'axios'
import {
useQuery,
useMutation
} from '@tanstack/react-query'
import type {
UseQueryOptions,
UseMutationOptions,
QueryFunction,
MutationFunction,
UseQueryResult,
QueryKey
} from '@tanstack/react-query'
import type {
Pet,
FindPetsByStatusParams,
FindPetsByTagsParams,
UpdatePetWithFormParams,
ApiResponse,
UploadFileParams,
GetInventory200,
Order,
User,
LoginUserParams
} from './swaggerPetstoreOpenAPI30.schemas'
type AwaitedInput<T> = PromiseLike<T> | T;
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
/**
* Update an existing pet by Id
* @summary Update an existing pet
*/
export const updatePet = (
pet: Pet, options?: AxiosRequestConfig
): Promise<AxiosResponse<Pet>> => {
return axios.put(
`/pet`,
pet,options
);
}
export const getUpdatePetMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: Pet}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: Pet}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updatePet>>, {data: Pet}> = (props) => {
const {data} = props ?? {};
return updatePet(data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type UpdatePetMutationResult = NonNullable<Awaited<ReturnType<typeof updatePet>>>
export type UpdatePetMutationBody = Pet
export type UpdatePetMutationError = AxiosError<void>
/**
* @summary Update an existing pet
*/
export const useUpdatePet = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: Pet}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getUpdatePetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Add a new pet to the store
* @summary Add a new pet to the store
*/
export const addPet = (
pet: Pet, options?: AxiosRequestConfig
): Promise<AxiosResponse<Pet>> => {
return axios.post(
`/pet`,
pet,options
);
}
export const getAddPetMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: Pet}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: Pet}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof addPet>>, {data: Pet}> = (props) => {
const {data} = props ?? {};
return addPet(data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type AddPetMutationResult = NonNullable<Awaited<ReturnType<typeof addPet>>>
export type AddPetMutationBody = Pet
export type AddPetMutationError = AxiosError<void>
/**
* @summary Add a new pet to the store
*/
export const useAddPet = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: Pet}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getAddPetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
*/
export const findPetsByStatus = (
params?: FindPetsByStatusParams, options?: AxiosRequestConfig
): Promise<AxiosResponse<Pet[]>> => {
return axios.get(
`/pet/findByStatus`,{
...options,
params: {...params, ...options?.params},}
);
}
export const getFindPetsByStatusQueryKey = (params?: FindPetsByStatusParams,) => [`/pet/findByStatus`, ...(params ? [params]: [])] as const;
export const getFindPetsByStatusQueryOptions = <TData = Awaited<ReturnType<typeof findPetsByStatus>>, TError = AxiosError<void>>(params?: FindPetsByStatusParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getFindPetsByStatusQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof findPetsByStatus>>> = ({ signal }) => findPetsByStatus(params, { signal, ...axiosOptions });
return { queryKey, queryFn, ...queryOptions}}
export type FindPetsByStatusQueryResult = NonNullable<Awaited<ReturnType<typeof findPetsByStatus>>>
export type FindPetsByStatusQueryError = AxiosError<void>
/**
* @summary Finds Pets by status
*/
export const useFindPetsByStatus = <TData = Awaited<ReturnType<typeof findPetsByStatus>>, TError = AxiosError<void>>(
params?: FindPetsByStatusParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getFindPetsByStatusQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
*/
export const findPetsByTags = (
params?: FindPetsByTagsParams, options?: AxiosRequestConfig
): Promise<AxiosResponse<Pet[]>> => {
return axios.get(
`/pet/findByTags`,{
...options,
params: {...params, ...options?.params},}
);
}
export const getFindPetsByTagsQueryKey = (params?: FindPetsByTagsParams,) => [`/pet/findByTags`, ...(params ? [params]: [])] as const;
export const getFindPetsByTagsQueryOptions = <TData = Awaited<ReturnType<typeof findPetsByTags>>, TError = AxiosError<void>>(params?: FindPetsByTagsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getFindPetsByTagsQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof findPetsByTags>>> = ({ signal }) => findPetsByTags(params, { signal, ...axiosOptions });
return { queryKey, queryFn, ...queryOptions}}
export type FindPetsByTagsQueryResult = NonNullable<Awaited<ReturnType<typeof findPetsByTags>>>
export type FindPetsByTagsQueryError = AxiosError<void>
/**
* @summary Finds Pets by tags
*/
export const useFindPetsByTags = <TData = Awaited<ReturnType<typeof findPetsByTags>>, TError = AxiosError<void>>(
params?: FindPetsByTagsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getFindPetsByTagsQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Returns a single pet
* @summary Find pet by ID
*/
export const getPetById = (
petId: number, options?: AxiosRequestConfig
): Promise<AxiosResponse<Pet>> => {
return axios.get(
`/pet/${petId}`,options
);
}
export const getGetPetByIdQueryKey = (petId: number,) => [`/pet/${petId}`] as const;
export const getGetPetByIdQueryOptions = <TData = Awaited<ReturnType<typeof getPetById>>, TError = AxiosError<void>>(petId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetPetByIdQueryKey(petId);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPetById>>> = ({ signal }) => getPetById(petId, { signal, ...axiosOptions });
return { queryKey, queryFn, enabled: !!(petId), ...queryOptions}}
export type GetPetByIdQueryResult = NonNullable<Awaited<ReturnType<typeof getPetById>>>
export type GetPetByIdQueryError = AxiosError<void>
/**
* @summary Find pet by ID
*/
export const useGetPetById = <TData = Awaited<ReturnType<typeof getPetById>>, TError = AxiosError<void>>(
petId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetPetByIdQueryOptions(petId,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Updates a pet in the store with form data
*/
export const updatePetWithForm = (
petId: number,
params?: UpdatePetWithFormParams, options?: AxiosRequestConfig
): Promise<AxiosResponse<unknown>> => {
return axios.post(
`/pet/${petId}`,undefined,{
...options,
params: {...params, ...options?.params},}
);
}
export const getUpdatePetWithFormMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updatePetWithForm>>, {petId: number;params?: UpdatePetWithFormParams}> = (props) => {
const {petId,params} = props ?? {};
return updatePetWithForm(petId,params,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type UpdatePetWithFormMutationResult = NonNullable<Awaited<ReturnType<typeof updatePetWithForm>>>
export type UpdatePetWithFormMutationError = AxiosError<void>
/**
* @summary Updates a pet in the store with form data
*/
export const useUpdatePetWithForm = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getUpdatePetWithFormMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* delete a pet
* @summary Deletes a pet
*/
export const deletePet = (
petId: number, options?: AxiosRequestConfig
): Promise<AxiosResponse<unknown>> => {
return axios.delete(
`/pet/${petId}`,options
);
}
export const getDeletePetMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deletePet>>, {petId: number}> = (props) => {
const {petId} = props ?? {};
return deletePet(petId,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type DeletePetMutationResult = NonNullable<Awaited<ReturnType<typeof deletePet>>>
export type DeletePetMutationError = AxiosError<void>
/**
* @summary Deletes a pet
*/
export const useDeletePet = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getDeletePetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* @summary uploads an image
*/
export const uploadFile = (
petId: number,
uploadFileBody: Blob,
params?: UploadFileParams, options?: AxiosRequestConfig
): Promise<AxiosResponse<ApiResponse>> => {
return axios.post(
`/pet/${petId}/uploadImage`,
uploadFileBody,{
...options,
params: {...params, ...options?.params},}
);
}
export const getUploadFileMutationOptions = <TError = AxiosError<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: Blob;params?: UploadFileParams}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: Blob;params?: UploadFileParams}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof uploadFile>>, {petId: number;data: Blob;params?: UploadFileParams}> = (props) => {
const {petId,data,params} = props ?? {};
return uploadFile(petId,data,params,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type UploadFileMutationResult = NonNullable<Awaited<ReturnType<typeof uploadFile>>>
export type UploadFileMutationBody = Blob
export type UploadFileMutationError = AxiosError<unknown>
/**
* @summary uploads an image
*/
export const useUploadFile = <TError = AxiosError<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: Blob;params?: UploadFileParams}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getUploadFileMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Returns a map of status codes to quantities
* @summary Returns pet inventories by status
*/
export const getInventory = (
options?: AxiosRequestConfig
): Promise<AxiosResponse<GetInventory200>> => {
return axios.get(
`/store/inventory`,options
);
}
export const getGetInventoryQueryKey = () => [`/store/inventory`] as const;
export const getGetInventoryQueryOptions = <TData = Awaited<ReturnType<typeof getInventory>>, TError = AxiosError<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetInventoryQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof getInventory>>> = ({ signal }) => getInventory({ signal, ...axiosOptions });
return { queryKey, queryFn, ...queryOptions}}
export type GetInventoryQueryResult = NonNullable<Awaited<ReturnType<typeof getInventory>>>
export type GetInventoryQueryError = AxiosError<unknown>
/**
* @summary Returns pet inventories by status
*/
export const useGetInventory = <TData = Awaited<ReturnType<typeof getInventory>>, TError = AxiosError<unknown>>(
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetInventoryQueryOptions(options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Place a new order in the store
* @summary Place an order for a pet
*/
export const placeOrder = (
order: Order, options?: AxiosRequestConfig
): Promise<AxiosResponse<Order>> => {
return axios.post(
`/store/order`,
order,options
);
}
export const getPlaceOrderMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: Order}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: Order}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof placeOrder>>, {data: Order}> = (props) => {
const {data} = props ?? {};
return placeOrder(data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type PlaceOrderMutationResult = NonNullable<Awaited<ReturnType<typeof placeOrder>>>
export type PlaceOrderMutationBody = Order
export type PlaceOrderMutationError = AxiosError<void>
/**
* @summary Place an order for a pet
*/
export const usePlaceOrder = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: Order}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getPlaceOrderMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
* @summary Find purchase order by ID
*/
export const getOrderById = (
orderId: number, options?: AxiosRequestConfig
): Promise<AxiosResponse<Order>> => {
return axios.get(
`/store/order/${orderId}`,options
);
}
export const getGetOrderByIdQueryKey = (orderId: number,) => [`/store/order/${orderId}`] as const;
export const getGetOrderByIdQueryOptions = <TData = Awaited<ReturnType<typeof getOrderById>>, TError = AxiosError<void>>(orderId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetOrderByIdQueryKey(orderId);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getOrderById>>> = ({ signal }) => getOrderById(orderId, { signal, ...axiosOptions });
return { queryKey, queryFn, enabled: !!(orderId), ...queryOptions}}
export type GetOrderByIdQueryResult = NonNullable<Awaited<ReturnType<typeof getOrderById>>>
export type GetOrderByIdQueryError = AxiosError<void>
/**
* @summary Find purchase order by ID
*/
export const useGetOrderById = <TData = Awaited<ReturnType<typeof getOrderById>>, TError = AxiosError<void>>(
orderId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetOrderByIdQueryOptions(orderId,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
* @summary Delete purchase order by ID
*/
export const deleteOrder = (
orderId: number, options?: AxiosRequestConfig
): Promise<AxiosResponse<unknown>> => {
return axios.delete(
`/store/order/${orderId}`,options
);
}
export const getDeleteOrderMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteOrder>>, {orderId: number}> = (props) => {
const {orderId} = props ?? {};
return deleteOrder(orderId,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type DeleteOrderMutationResult = NonNullable<Awaited<ReturnType<typeof deleteOrder>>>
export type DeleteOrderMutationError = AxiosError<void>
/**
* @summary Delete purchase order by ID
*/
export const useDeleteOrder = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getDeleteOrderMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* This can only be done by the logged in user.
* @summary Create user
*/
export const createUser = (
user: User, options?: AxiosRequestConfig
): Promise<AxiosResponse<User>> => {
return axios.post(
`/user`,
user,options
);
}
export const getCreateUserMutationOptions = <TError = AxiosError<User>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: User}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: User}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUser>>, {data: User}> = (props) => {
const {data} = props ?? {};
return createUser(data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type CreateUserMutationResult = NonNullable<Awaited<ReturnType<typeof createUser>>>
export type CreateUserMutationBody = User
export type CreateUserMutationError = AxiosError<User>
/**
* @summary Create user
*/
export const useCreateUser = <TError = AxiosError<User>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: User}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getCreateUserMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Creates list of users with given input array
* @summary Creates list of users with given input array
*/
export const createUsersWithListInput = (
user: User[], options?: AxiosRequestConfig
): Promise<AxiosResponse<User>> => {
return axios.post(
`/user/createWithList`,
user,options
);
}
export const getCreateUsersWithListInputMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: User[]}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: User[]}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUsersWithListInput>>, {data: User[]}> = (props) => {
const {data} = props ?? {};
return createUsersWithListInput(data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type CreateUsersWithListInputMutationResult = NonNullable<Awaited<ReturnType<typeof createUsersWithListInput>>>
export type CreateUsersWithListInputMutationBody = User[]
export type CreateUsersWithListInputMutationError = AxiosError<void>
/**
* @summary Creates list of users with given input array
*/
export const useCreateUsersWithListInput = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: User[]}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getCreateUsersWithListInputMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* @summary Logs user into the system
*/
export const loginUser = (
params?: LoginUserParams, options?: AxiosRequestConfig
): Promise<AxiosResponse<string>> => {
return axios.get(
`/user/login`,{
...options,
params: {...params, ...options?.params},}
);
}
export const getLoginUserQueryKey = (params?: LoginUserParams,) => [`/user/login`, ...(params ? [params]: [])] as const;
export const getLoginUserQueryOptions = <TData = Awaited<ReturnType<typeof loginUser>>, TError = AxiosError<void>>(params?: LoginUserParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getLoginUserQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof loginUser>>> = ({ signal }) => loginUser(params, { signal, ...axiosOptions });
return { queryKey, queryFn, ...queryOptions}}
export type LoginUserQueryResult = NonNullable<Awaited<ReturnType<typeof loginUser>>>
export type LoginUserQueryError = AxiosError<void>
/**
* @summary Logs user into the system
*/
export const useLoginUser = <TData = Awaited<ReturnType<typeof loginUser>>, TError = AxiosError<void>>(
params?: LoginUserParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getLoginUserQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Logs out current logged in user session
*/
export const logoutUser = (
options?: AxiosRequestConfig
): Promise<AxiosResponse<void>> => {
return axios.get(
`/user/logout`,options
);
}
export const getLogoutUserQueryKey = () => [`/user/logout`] as const;
export const getLogoutUserQueryOptions = <TData = Awaited<ReturnType<typeof logoutUser>>, TError = AxiosError<void>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getLogoutUserQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof logoutUser>>> = ({ signal }) => logoutUser({ signal, ...axiosOptions });
return { queryKey, queryFn, ...queryOptions}}
export type LogoutUserQueryResult = NonNullable<Awaited<ReturnType<typeof logoutUser>>>
export type LogoutUserQueryError = AxiosError<void>
/**
* @summary Logs out current logged in user session
*/
export const useLogoutUser = <TData = Awaited<ReturnType<typeof logoutUser>>, TError = AxiosError<void>>(
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getLogoutUserQueryOptions(options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get user by user name
*/
export const getUserByName = (
username: string, options?: AxiosRequestConfig
): Promise<AxiosResponse<User>> => {
return axios.get(
`/user/${username}`,options
);
}
export const getGetUserByNameQueryKey = (username: string,) => [`/user/${username}`] as const;
export const getGetUserByNameQueryOptions = <TData = Awaited<ReturnType<typeof getUserByName>>, TError = AxiosError<void>>(username: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions, axios: axiosOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetUserByNameQueryKey(username);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getUserByName>>> = ({ signal }) => getUserByName(username, { signal, ...axiosOptions });
return { queryKey, queryFn, enabled: !!(username), ...queryOptions}}
export type GetUserByNameQueryResult = NonNullable<Awaited<ReturnType<typeof getUserByName>>>
export type GetUserByNameQueryError = AxiosError<void>
/**
* @summary Get user by user name
*/
export const useGetUserByName = <TData = Awaited<ReturnType<typeof getUserByName>>, TError = AxiosError<void>>(
username: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData>, axios?: AxiosRequestConfig}
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetUserByNameQueryOptions(username,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* This can only be done by the logged in user.
* @summary Update user
*/
export const updateUser = (
username: string,
user: User, options?: AxiosRequestConfig
): Promise<AxiosResponse<void>> => {
return axios.put(
`/user/${username}`,
user,options
);
}
export const getUpdateUserMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: User}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: User}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateUser>>, {username: string;data: User}> = (props) => {
const {username,data} = props ?? {};
return updateUser(username,data,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type UpdateUserMutationResult = NonNullable<Awaited<ReturnType<typeof updateUser>>>
export type UpdateUserMutationBody = User
export type UpdateUserMutationError = AxiosError<void>
/**
* @summary Update user
*/
export const useUpdateUser = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: User}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getUpdateUserMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* This can only be done by the logged in user.
* @summary Delete user
*/
export const deleteUser = (
username: string, options?: AxiosRequestConfig
): Promise<AxiosResponse<unknown>> => {
return axios.delete(
`/user/${username}`,options
);
}
export const getDeleteUserMutationOptions = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext>, axios?: AxiosRequestConfig}
): UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext> => {
const {mutation: mutationOptions, axios: axiosOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteUser>>, {username: string}> = (props) => {
const {username} = props ?? {};
return deleteUser(username,axiosOptions)
}
return { mutationFn, ...mutationOptions }}
export type DeleteUserMutationResult = NonNullable<Awaited<ReturnType<typeof deleteUser>>>
export type DeleteUserMutationError = AxiosError<void>
/**
* @summary Delete user
*/
export const useDeleteUser = <TError = AxiosError<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext>, axios?: AxiosRequestConfig}
) => {
const mutationOptions = getDeleteUserMutationOptions(options);
return useMutation(mutationOptions);
}
</details>
- 課題
- 型だけを取り扱いたい場合に、クライアントコードまで生成されてしまう問題
- BE観点で扱いやすいかどうか
- HTTPクライアントがデフォルトだとaxiosだが、それ以外を利用したい場合は独自にカスタムが必要?
- [https://orval.dev/guides/custom-client](https://orval.dev/guides/custom-client)
- example通りに設定するとaxiosではなくなった
<details>
<summary>swaggerPetstoreOpenAPI30.ts</summary>
/**
* Generated by orval v6.17.0 🍺
* Do not edit manually.
* Swagger Petstore - OpenAPI 3.0
* This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
_If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
* OpenAPI spec version: 1.0.11
*/
import {
useQuery,
useMutation
} from '@tanstack/react-query'
import type {
UseQueryOptions,
UseMutationOptions,
QueryFunction,
MutationFunction,
UseQueryResult,
QueryKey
} from '@tanstack/react-query'
import type {
Pet,
FindPetsByStatusParams,
FindPetsByTagsParams,
UpdatePetWithFormParams,
ApiResponse,
UploadFileParams,
GetInventory200,
Order,
User,
LoginUserParams
} from './swaggerPetstoreOpenAPI30.schemas'
import { customInstance } from '../custom-instance';
import type { ErrorType, BodyType } from '../custom-instance';
type AwaitedInput<T> = PromiseLike<T> | T;
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
/**
* Update an existing pet by Id
* @summary Update an existing pet
*/
export const updatePet = (
pet: BodyType<Pet>,
) => {
return customInstance<Pet>(
{url: `/pet`, method: 'put',
headers: {'Content-Type': 'application/json', },
data: pet
},
);
}
export const getUpdatePetMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: BodyType<Pet>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: BodyType<Pet>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updatePet>>, {data: BodyType<Pet>}> = (props) => {
const {data} = props ?? {};
return updatePet(data,)
}
return { mutationFn, ...mutationOptions }}
export type UpdatePetMutationResult = NonNullable<Awaited<ReturnType<typeof updatePet>>>
export type UpdatePetMutationBody = BodyType<Pet>
export type UpdatePetMutationError = ErrorType<void>
/**
* @summary Update an existing pet
*/
export const useUpdatePet = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePet>>, TError,{data: BodyType<Pet>}, TContext>, }
) => {
const mutationOptions = getUpdatePetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Add a new pet to the store
* @summary Add a new pet to the store
*/
export const addPet = (
pet: BodyType<Pet>,
) => {
return customInstance<Pet>(
{url: `/pet`, method: 'post',
headers: {'Content-Type': 'application/json', },
data: pet
},
);
}
export const getAddPetMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: BodyType<Pet>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: BodyType<Pet>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof addPet>>, {data: BodyType<Pet>}> = (props) => {
const {data} = props ?? {};
return addPet(data,)
}
return { mutationFn, ...mutationOptions }}
export type AddPetMutationResult = NonNullable<Awaited<ReturnType<typeof addPet>>>
export type AddPetMutationBody = BodyType<Pet>
export type AddPetMutationError = ErrorType<void>
/**
* @summary Add a new pet to the store
*/
export const useAddPet = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof addPet>>, TError,{data: BodyType<Pet>}, TContext>, }
) => {
const mutationOptions = getAddPetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
*/
export const findPetsByStatus = (
params?: FindPetsByStatusParams,
signal?: AbortSignal
) => {
return customInstance<Pet[]>(
{url: `/pet/findByStatus`, method: 'get',
params, signal
},
);
}
export const getFindPetsByStatusQueryKey = (params?: FindPetsByStatusParams,) => [`/pet/findByStatus`, ...(params ? [params]: [])] as const;
export const getFindPetsByStatusQueryOptions = <TData = Awaited<ReturnType<typeof findPetsByStatus>>, TError = ErrorType<void>>(params?: FindPetsByStatusParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getFindPetsByStatusQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof findPetsByStatus>>> = ({ signal }) => findPetsByStatus(params, signal);
return { queryKey, queryFn, ...queryOptions}}
export type FindPetsByStatusQueryResult = NonNullable<Awaited<ReturnType<typeof findPetsByStatus>>>
export type FindPetsByStatusQueryError = ErrorType<void>
/**
* @summary Finds Pets by status
*/
export const useFindPetsByStatus = <TData = Awaited<ReturnType<typeof findPetsByStatus>>, TError = ErrorType<void>>(
params?: FindPetsByStatusParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByStatus>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getFindPetsByStatusQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
*/
export const findPetsByTags = (
params?: FindPetsByTagsParams,
signal?: AbortSignal
) => {
return customInstance<Pet[]>(
{url: `/pet/findByTags`, method: 'get',
params, signal
},
);
}
export const getFindPetsByTagsQueryKey = (params?: FindPetsByTagsParams,) => [`/pet/findByTags`, ...(params ? [params]: [])] as const;
export const getFindPetsByTagsQueryOptions = <TData = Awaited<ReturnType<typeof findPetsByTags>>, TError = ErrorType<void>>(params?: FindPetsByTagsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getFindPetsByTagsQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof findPetsByTags>>> = ({ signal }) => findPetsByTags(params, signal);
return { queryKey, queryFn, ...queryOptions}}
export type FindPetsByTagsQueryResult = NonNullable<Awaited<ReturnType<typeof findPetsByTags>>>
export type FindPetsByTagsQueryError = ErrorType<void>
/**
* @summary Finds Pets by tags
*/
export const useFindPetsByTags = <TData = Awaited<ReturnType<typeof findPetsByTags>>, TError = ErrorType<void>>(
params?: FindPetsByTagsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof findPetsByTags>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getFindPetsByTagsQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Returns a single pet
* @summary Find pet by ID
*/
export const getPetById = (
petId: number,
signal?: AbortSignal
) => {
return customInstance<Pet>(
{url: `/pet/${petId}`, method: 'get', signal
},
);
}
export const getGetPetByIdQueryKey = (petId: number,) => [`/pet/${petId}`] as const;
export const getGetPetByIdQueryOptions = <TData = Awaited<ReturnType<typeof getPetById>>, TError = ErrorType<void>>(petId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetPetByIdQueryKey(petId);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPetById>>> = ({ signal }) => getPetById(petId, signal);
return { queryKey, queryFn, enabled: !!(petId), ...queryOptions}}
export type GetPetByIdQueryResult = NonNullable<Awaited<ReturnType<typeof getPetById>>>
export type GetPetByIdQueryError = ErrorType<void>
/**
* @summary Find pet by ID
*/
export const useGetPetById = <TData = Awaited<ReturnType<typeof getPetById>>, TError = ErrorType<void>>(
petId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getPetById>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetPetByIdQueryOptions(petId,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Updates a pet in the store with form data
*/
export const updatePetWithForm = (
petId: number,
params?: UpdatePetWithFormParams,
) => {
return customInstance<unknown>(
{url: `/pet/${petId}`, method: 'post',
params
},
);
}
export const getUpdatePetWithFormMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updatePetWithForm>>, {petId: number;params?: UpdatePetWithFormParams}> = (props) => {
const {petId,params} = props ?? {};
return updatePetWithForm(petId,params,)
}
return { mutationFn, ...mutationOptions }}
export type UpdatePetWithFormMutationResult = NonNullable<Awaited<ReturnType<typeof updatePetWithForm>>>
export type UpdatePetWithFormMutationError = ErrorType<void>
/**
* @summary Updates a pet in the store with form data
*/
export const useUpdatePetWithForm = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updatePetWithForm>>, TError,{petId: number;params?: UpdatePetWithFormParams}, TContext>, }
) => {
const mutationOptions = getUpdatePetWithFormMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* delete a pet
* @summary Deletes a pet
*/
export const deletePet = (
petId: number,
) => {
return customInstance<unknown>(
{url: `/pet/${petId}`, method: 'delete'
},
);
}
export const getDeletePetMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deletePet>>, {petId: number}> = (props) => {
const {petId} = props ?? {};
return deletePet(petId,)
}
return { mutationFn, ...mutationOptions }}
export type DeletePetMutationResult = NonNullable<Awaited<ReturnType<typeof deletePet>>>
export type DeletePetMutationError = ErrorType<void>
/**
* @summary Deletes a pet
*/
export const useDeletePet = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePet>>, TError,{petId: number}, TContext>, }
) => {
const mutationOptions = getDeletePetMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* @summary uploads an image
*/
export const uploadFile = (
petId: number,
uploadFileBody: BodyType<Blob>,
params?: UploadFileParams,
) => {
return customInstance<ApiResponse>(
{url: `/pet/${petId}/uploadImage`, method: 'post',
headers: {'Content-Type': 'application/octet-stream', },
data: uploadFileBody,
params
},
);
}
export const getUploadFileMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: BodyType<Blob>;params?: UploadFileParams}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: BodyType<Blob>;params?: UploadFileParams}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof uploadFile>>, {petId: number;data: BodyType<Blob>;params?: UploadFileParams}> = (props) => {
const {petId,data,params} = props ?? {};
return uploadFile(petId,data,params,)
}
return { mutationFn, ...mutationOptions }}
export type UploadFileMutationResult = NonNullable<Awaited<ReturnType<typeof uploadFile>>>
export type UploadFileMutationBody = BodyType<Blob>
export type UploadFileMutationError = ErrorType<unknown>
/**
* @summary uploads an image
*/
export const useUploadFile = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadFile>>, TError,{petId: number;data: BodyType<Blob>;params?: UploadFileParams}, TContext>, }
) => {
const mutationOptions = getUploadFileMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Returns a map of status codes to quantities
* @summary Returns pet inventories by status
*/
export const getInventory = (
signal?: AbortSignal
) => {
return customInstance<GetInventory200>(
{url: `/store/inventory`, method: 'get', signal
},
);
}
export const getGetInventoryQueryKey = () => [`/store/inventory`] as const;
export const getGetInventoryQueryOptions = <TData = Awaited<ReturnType<typeof getInventory>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetInventoryQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof getInventory>>> = ({ signal }) => getInventory(signal);
return { queryKey, queryFn, ...queryOptions}}
export type GetInventoryQueryResult = NonNullable<Awaited<ReturnType<typeof getInventory>>>
export type GetInventoryQueryError = ErrorType<unknown>
/**
* @summary Returns pet inventories by status
*/
export const useGetInventory = <TData = Awaited<ReturnType<typeof getInventory>>, TError = ErrorType<unknown>>(
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getInventory>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetInventoryQueryOptions(options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* Place a new order in the store
* @summary Place an order for a pet
*/
export const placeOrder = (
order: BodyType<Order>,
) => {
return customInstance<Order>(
{url: `/store/order`, method: 'post',
headers: {'Content-Type': 'application/json', },
data: order
},
);
}
export const getPlaceOrderMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: BodyType<Order>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: BodyType<Order>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof placeOrder>>, {data: BodyType<Order>}> = (props) => {
const {data} = props ?? {};
return placeOrder(data,)
}
return { mutationFn, ...mutationOptions }}
export type PlaceOrderMutationResult = NonNullable<Awaited<ReturnType<typeof placeOrder>>>
export type PlaceOrderMutationBody = BodyType<Order>
export type PlaceOrderMutationError = ErrorType<void>
/**
* @summary Place an order for a pet
*/
export const usePlaceOrder = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof placeOrder>>, TError,{data: BodyType<Order>}, TContext>, }
) => {
const mutationOptions = getPlaceOrderMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
* @summary Find purchase order by ID
*/
export const getOrderById = (
orderId: number,
signal?: AbortSignal
) => {
return customInstance<Order>(
{url: `/store/order/${orderId}`, method: 'get', signal
},
);
}
export const getGetOrderByIdQueryKey = (orderId: number,) => [`/store/order/${orderId}`] as const;
export const getGetOrderByIdQueryOptions = <TData = Awaited<ReturnType<typeof getOrderById>>, TError = ErrorType<void>>(orderId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetOrderByIdQueryKey(orderId);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getOrderById>>> = ({ signal }) => getOrderById(orderId, signal);
return { queryKey, queryFn, enabled: !!(orderId), ...queryOptions}}
export type GetOrderByIdQueryResult = NonNullable<Awaited<ReturnType<typeof getOrderById>>>
export type GetOrderByIdQueryError = ErrorType<void>
/**
* @summary Find purchase order by ID
*/
export const useGetOrderById = <TData = Awaited<ReturnType<typeof getOrderById>>, TError = ErrorType<void>>(
orderId: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getOrderById>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetOrderByIdQueryOptions(orderId,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
* @summary Delete purchase order by ID
*/
export const deleteOrder = (
orderId: number,
) => {
return customInstance<unknown>(
{url: `/store/order/${orderId}`, method: 'delete'
},
);
}
export const getDeleteOrderMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteOrder>>, {orderId: number}> = (props) => {
const {orderId} = props ?? {};
return deleteOrder(orderId,)
}
return { mutationFn, ...mutationOptions }}
export type DeleteOrderMutationResult = NonNullable<Awaited<ReturnType<typeof deleteOrder>>>
export type DeleteOrderMutationError = ErrorType<void>
/**
* @summary Delete purchase order by ID
*/
export const useDeleteOrder = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteOrder>>, TError,{orderId: number}, TContext>, }
) => {
const mutationOptions = getDeleteOrderMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* This can only be done by the logged in user.
* @summary Create user
*/
export const createUser = (
user: BodyType<User>,
) => {
return customInstance<User>(
{url: `/user`, method: 'post',
headers: {'Content-Type': 'application/json', },
data: user
},
);
}
export const getCreateUserMutationOptions = <TError = ErrorType<User>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<User>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<User>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUser>>, {data: BodyType<User>}> = (props) => {
const {data} = props ?? {};
return createUser(data,)
}
return { mutationFn, ...mutationOptions }}
export type CreateUserMutationResult = NonNullable<Awaited<ReturnType<typeof createUser>>>
export type CreateUserMutationBody = BodyType<User>
export type CreateUserMutationError = ErrorType<User>
/**
* @summary Create user
*/
export const useCreateUser = <TError = ErrorType<User>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<User>}, TContext>, }
) => {
const mutationOptions = getCreateUserMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* Creates list of users with given input array
* @summary Creates list of users with given input array
*/
export const createUsersWithListInput = (
user: User[],
) => {
return customInstance<User>(
{url: `/user/createWithList`, method: 'post',
headers: {'Content-Type': 'application/json', },
data: user
},
);
}
export const getCreateUsersWithListInputMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: BodyType<User[]>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: BodyType<User[]>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUsersWithListInput>>, {data: BodyType<User[]>}> = (props) => {
const {data} = props ?? {};
return createUsersWithListInput(data,)
}
return { mutationFn, ...mutationOptions }}
export type CreateUsersWithListInputMutationResult = NonNullable<Awaited<ReturnType<typeof createUsersWithListInput>>>
export type CreateUsersWithListInputMutationBody = BodyType<User[]>
export type CreateUsersWithListInputMutationError = ErrorType<void>
/**
* @summary Creates list of users with given input array
*/
export const useCreateUsersWithListInput = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUsersWithListInput>>, TError,{data: BodyType<User[]>}, TContext>, }
) => {
const mutationOptions = getCreateUsersWithListInputMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* @summary Logs user into the system
*/
export const loginUser = (
params?: LoginUserParams,
signal?: AbortSignal
) => {
return customInstance<string>(
{url: `/user/login`, method: 'get',
params, signal
},
);
}
export const getLoginUserQueryKey = (params?: LoginUserParams,) => [`/user/login`, ...(params ? [params]: [])] as const;
export const getLoginUserQueryOptions = <TData = Awaited<ReturnType<typeof loginUser>>, TError = ErrorType<void>>(params?: LoginUserParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getLoginUserQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof loginUser>>> = ({ signal }) => loginUser(params, signal);
return { queryKey, queryFn, ...queryOptions}}
export type LoginUserQueryResult = NonNullable<Awaited<ReturnType<typeof loginUser>>>
export type LoginUserQueryError = ErrorType<void>
/**
* @summary Logs user into the system
*/
export const useLoginUser = <TData = Awaited<ReturnType<typeof loginUser>>, TError = ErrorType<void>>(
params?: LoginUserParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof loginUser>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getLoginUserQueryOptions(params,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Logs out current logged in user session
*/
export const logoutUser = (
signal?: AbortSignal
) => {
return customInstance<void>(
{url: `/user/logout`, method: 'get', signal
},
);
}
export const getLogoutUserQueryKey = () => [`/user/logout`] as const;
export const getLogoutUserQueryOptions = <TData = Awaited<ReturnType<typeof logoutUser>>, TError = ErrorType<void>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getLogoutUserQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof logoutUser>>> = ({ signal }) => logoutUser(signal);
return { queryKey, queryFn, ...queryOptions}}
export type LogoutUserQueryResult = NonNullable<Awaited<ReturnType<typeof logoutUser>>>
export type LogoutUserQueryError = ErrorType<void>
/**
* @summary Logs out current logged in user session
*/
export const useLogoutUser = <TData = Awaited<ReturnType<typeof logoutUser>>, TError = ErrorType<void>>(
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof logoutUser>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getLogoutUserQueryOptions(options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get user by user name
*/
export const getUserByName = (
username: string,
signal?: AbortSignal
) => {
return customInstance<User>(
{url: `/user/${username}`, method: 'get', signal
},
);
}
export const getGetUserByNameQueryKey = (username: string,) => [`/user/${username}`] as const;
export const getGetUserByNameQueryOptions = <TData = Awaited<ReturnType<typeof getUserByName>>, TError = ErrorType<void>>(username: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData>, }
): UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData> & { queryKey: QueryKey } => {
const {query: queryOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetUserByNameQueryKey(username);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getUserByName>>> = ({ signal }) => getUserByName(username, signal);
return { queryKey, queryFn, enabled: !!(username), ...queryOptions}}
export type GetUserByNameQueryResult = NonNullable<Awaited<ReturnType<typeof getUserByName>>>
export type GetUserByNameQueryError = ErrorType<void>
/**
* @summary Get user by user name
*/
export const useGetUserByName = <TData = Awaited<ReturnType<typeof getUserByName>>, TError = ErrorType<void>>(
username: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getUserByName>>, TError, TData>, }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
const queryOptions = getGetUserByNameQueryOptions(username,options)
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* This can only be done by the logged in user.
* @summary Update user
*/
export const updateUser = (
username: string,
user: BodyType<User>,
) => {
return customInstance<void>(
{url: `/user/${username}`, method: 'put',
headers: {'Content-Type': 'application/json', },
data: user
},
);
}
export const getUpdateUserMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: BodyType<User>}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: BodyType<User>}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateUser>>, {username: string;data: BodyType<User>}> = (props) => {
const {username,data} = props ?? {};
return updateUser(username,data,)
}
return { mutationFn, ...mutationOptions }}
export type UpdateUserMutationResult = NonNullable<Awaited<ReturnType<typeof updateUser>>>
export type UpdateUserMutationBody = BodyType<User>
export type UpdateUserMutationError = ErrorType<void>
/**
* @summary Update user
*/
export const useUpdateUser = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{username: string;data: BodyType<User>}, TContext>, }
) => {
const mutationOptions = getUpdateUserMutationOptions(options);
return useMutation(mutationOptions);
}
/**
* This can only be done by the logged in user.
* @summary Delete user
*/
export const deleteUser = (
username: string,
) => {
return customInstance<unknown>(
{url: `/user/${username}`, method: 'delete'
},
);
}
export const getDeleteUserMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext>, }
): UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext> => {
const {mutation: mutationOptions} = options ?? {};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteUser>>, {username: string}> = (props) => {
const {username} = props ?? {};
return deleteUser(username,)
}
return { mutationFn, ...mutationOptions }}
export type DeleteUserMutationResult = NonNullable<Awaited<ReturnType<typeof deleteUser>>>
export type DeleteUserMutationError = ErrorType<void>
/**
* @summary Delete user
*/
export const useDeleteUser = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{username: string}, TContext>, }
) => {
const mutationOptions = getDeleteUserMutationOptions(options);
return useMutation(mutationOptions);
}
</details>
- まとめ
- 型生成 ~ クライアントコード生成、モック、hooksなどFEにとっては多機能
- 課題がいくつかある
- シンプルに型生成だけしたい場合は不向きかも
- リンク
- [https://orval.dev/](https://orval.dev/)
aspida
- これは何
- ブラウザーおよびnode.js用のTypeScriptフレンドリーなHTTPクライアントラッパー
- axios / fetch / node-fetchをサポートする
- 型生成は[https://github.com/aspida/openapi2aspida](https://github.com/aspida/openapi2aspida)を使うため、aspidaとセットで利用することになる
- 型生成機としてだけ使えるかどうかは議論点の1つ
- 日本語ドキュメントあり
- ただし情報薄め
- 使い方
- cli (+ config)による生成
- 生成した型
- apiディレクトリに生成される
<details>
<summary>@types/index.ts</summary>
/* eslint-disable */
export type Order = {
id?: number | undefined
petId?: number | undefined
quantity?: number | undefined
shipDate?: string | undefined
/** Order Status */
status?: 'placed' | 'approved' | 'delivered' | undefined
complete?: boolean | undefined
}
export type Customer = {
id?: number | undefined
username?: string | undefined
address?: Address[] | undefined
}
export type Address = {
street?: string | undefined
city?: string | undefined
state?: string | undefined
zip?: string | undefined
}
export type Category = {
id?: number | undefined
name?: string | undefined
}
export type User = {
id?: number | undefined
username?: string | undefined
firstName?: string | undefined
lastName?: string | undefined
email?: string | undefined
password?: string | undefined
phone?: string | undefined
/** User Status */
userStatus?: number | undefined
}
export type Tag = {
id?: number | undefined
name?: string | undefined
}
export type Pet = {
id?: number | undefined
name: string
category?: Category | undefined
photoUrls: string[]
tags?: Tag[] | undefined
/** pet status in the store */
status?: 'available' | 'pending' | 'sold' | undefined
}
export type ApiResponse = {
code?: number | undefined
type?: string | undefined
message?: string | undefined
}
export type Pet = Pet
export type UserArray = User[]
</details>
<details>
<summary>pet/findByStatus/index.ts(一例)</summary>
/* eslint-disable */
import type * as Types from '../../@types'
export type Methods = {
/** Multiple status values can be provided with comma separated strings */
get: {
query?: {
/** Status values that need to be considered for filter */
status?: 'available' | 'pending' | 'sold' | undefined
} | undefined
status: 200
/** successful operation */
resBody: Types.Pet[]
}
}
</details>
<details>
<summary>$api.ts</summary>
import type { AspidaClient, BasicHeaders } from 'aspida';
import { dataToURLString } from 'aspida';
import type { Methods as Methods0 } from './pet';
import type { Methods as Methods1 } from './pet/_petId@number';
import type { Methods as Methods2 } from './pet/_petId@number/uploadImage';
import type { Methods as Methods3 } from './pet/findByStatus';
import type { Methods as Methods4 } from './pet/findByTags';
import type { Methods as Methods5 } from './store/inventory';
import type { Methods as Methods6 } from './store/order';
import type { Methods as Methods7 } from './store/order/_orderId@number';
import type { Methods as Methods8 } from './user';
import type { Methods as Methods9 } from './user/_username@string';
import type { Methods as Methods10 } from './user/createWithList';
import type { Methods as Methods11 } from './user/login';
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
const prefix = (baseURL === undefined ? 'https://petstore3.swagger.io/api/v3' : baseURL).replace(/\/$/, '');
const PATH0 = '/pet';
const PATH1 = '/uploadImage';
const PATH2 = '/pet/findByStatus';
const PATH3 = '/pet/findByTags';
const PATH4 = '/store/inventory';
const PATH5 = '/store/order';
const PATH6 = '/user';
const PATH7 = '/user/createWithList';
const PATH8 = '/user/login';
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
return {
pet: {
_petId: (val1: number) => {
const prefix1 = `${PATH0}/${val1}`;
return {
uploadImage: {
/**
* @returns successful operation
*/
post: (option: { body: Methods2['post']['reqBody'], query?: Methods2['post']['query'] | undefined, config?: T | undefined }) =>
fetch<Methods2['post']['resBody'], BasicHeaders, Methods2['post']['status']>(prefix, `${prefix1}${PATH1}`, POST, option).json(),
/**
* @returns successful operation
*/
$post: (option: { body: Methods2['post']['reqBody'], query?: Methods2['post']['query'] | undefined, config?: T | undefined }) =>
fetch<Methods2['post']['resBody'], BasicHeaders, Methods2['post']['status']>(prefix, `${prefix1}${PATH1}`, POST, option).json().then(r => r.body),
$path: (option?: { method: 'post'; query: Methods2['post']['query'] } | undefined) =>
`${prefix}${prefix1}${PATH1}${option && option.query ? `?${dataToURLString(option.query)}` : ''}`,
},
/**
* Returns a single pet
* @returns successful operation
*/
get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods1['get']['resBody'], BasicHeaders, Methods1['get']['status']>(prefix, prefix1, GET, option).json(),
/**
* Returns a single pet
* @returns successful operation
*/
$get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods1['get']['resBody'], BasicHeaders, Methods1['get']['status']>(prefix, prefix1, GET, option).json().then(r => r.body),
post: (option?: { query?: Methods1['post']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, POST, option).send(),
$post: (option?: { query?: Methods1['post']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, POST, option).send().then(r => r.body),
/**
* delete a pet
*/
delete: (option?: { headers?: Methods1['delete']['reqHeaders'] | undefined, config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, DELETE, option).send(),
/**
* delete a pet
*/
$delete: (option?: { headers?: Methods1['delete']['reqHeaders'] | undefined, config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, DELETE, option).send().then(r => r.body),
$path: (option?: { method: 'post'; query: Methods1['post']['query'] } | undefined) =>
`${prefix}${prefix1}${option && option.query ? `?${dataToURLString(option.query)}` : ''}`,
};
},
findByStatus: {
/**
* Multiple status values can be provided with comma separated strings
* @returns successful operation
*/
get: (option?: { query?: Methods3['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods3['get']['resBody'], BasicHeaders, Methods3['get']['status']>(prefix, PATH2, GET, option).json(),
/**
* Multiple status values can be provided with comma separated strings
* @returns successful operation
*/
$get: (option?: { query?: Methods3['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods3['get']['resBody'], BasicHeaders, Methods3['get']['status']>(prefix, PATH2, GET, option).json().then(r => r.body),
$path: (option?: { method?: 'get' | undefined; query: Methods3['get']['query'] } | undefined) =>
`${prefix}${PATH2}${option && option.query ? `?${dataToURLString(option.query)}` : ''}`,
},
findByTags: {
/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @returns successful operation
*/
get: (option?: { query?: Methods4['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods4['get']['resBody'], BasicHeaders, Methods4['get']['status']>(prefix, PATH3, GET, option).json(),
/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @returns successful operation
*/
$get: (option?: { query?: Methods4['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods4['get']['resBody'], BasicHeaders, Methods4['get']['status']>(prefix, PATH3, GET, option).json().then(r => r.body),
$path: (option?: { method?: 'get' | undefined; query: Methods4['get']['query'] } | undefined) =>
`${prefix}${PATH3}${option && option.query ? `?${dataToURLString(option.query)}` : ''}`,
},
/**
* Update an existing pet by Id
* @param option.body - Update an existent pet in the store
* @returns Successful operation
*/
put: (option: { body: Methods0['put']['reqBody'], config?: T | undefined }) =>
fetch<Methods0['put']['resBody'], BasicHeaders, Methods0['put']['status']>(prefix, PATH0, PUT, option, 'URLSearchParams').json(),
/**
* Update an existing pet by Id
* @param option.body - Update an existent pet in the store
* @returns Successful operation
*/
$put: (option: { body: Methods0['put']['reqBody'], config?: T | undefined }) =>
fetch<Methods0['put']['resBody'], BasicHeaders, Methods0['put']['status']>(prefix, PATH0, PUT, option, 'URLSearchParams').json().then(r => r.body),
/**
* Add a new pet to the store
* @param option.body - Create a new pet in the store
* @returns Successful operation
*/
post: (option: { body: Methods0['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods0['post']['resBody'], BasicHeaders, Methods0['post']['status']>(prefix, PATH0, POST, option, 'URLSearchParams').json(),
/**
* Add a new pet to the store
* @param option.body - Create a new pet in the store
* @returns Successful operation
*/
$post: (option: { body: Methods0['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods0['post']['resBody'], BasicHeaders, Methods0['post']['status']>(prefix, PATH0, POST, option, 'URLSearchParams').json().then(r => r.body),
$path: () => `${prefix}${PATH0}`,
},
store: {
inventory: {
/**
* Returns a map of status codes to quantities
* @returns successful operation
*/
get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods5['get']['resBody'], BasicHeaders, Methods5['get']['status']>(prefix, PATH4, GET, option).json(),
/**
* Returns a map of status codes to quantities
* @returns successful operation
*/
$get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods5['get']['resBody'], BasicHeaders, Methods5['get']['status']>(prefix, PATH4, GET, option).json().then(r => r.body),
$path: () => `${prefix}${PATH4}`,
},
order: {
_orderId: (val2: number) => {
const prefix2 = `${PATH5}/${val2}`;
return {
/**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
* @returns successful operation
*/
get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods7['get']['resBody'], BasicHeaders, Methods7['get']['status']>(prefix, prefix2, GET, option).json(),
/**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
* @returns successful operation
*/
$get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods7['get']['resBody'], BasicHeaders, Methods7['get']['status']>(prefix, prefix2, GET, option).json().then(r => r.body),
/**
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*/
delete: (option?: { config?: T | undefined } | undefined) =>
fetch(prefix, prefix2, DELETE, option).send(),
/**
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*/
$delete: (option?: { config?: T | undefined } | undefined) =>
fetch(prefix, prefix2, DELETE, option).send().then(r => r.body),
$path: () => `${prefix}${prefix2}`,
};
},
/**
* Place a new order in the store
* @returns successful operation
*/
post: (option: { body: Methods6['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods6['post']['resBody'], BasicHeaders, Methods6['post']['status']>(prefix, PATH5, POST, option, 'URLSearchParams').json(),
/**
* Place a new order in the store
* @returns successful operation
*/
$post: (option: { body: Methods6['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods6['post']['resBody'], BasicHeaders, Methods6['post']['status']>(prefix, PATH5, POST, option, 'URLSearchParams').json().then(r => r.body),
$path: () => `${prefix}${PATH5}`,
},
},
user: {
_username: (val1: string) => {
const prefix1 = `${PATH6}/${val1}`;
return {
/**
* @returns successful operation
*/
get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods9['get']['resBody'], BasicHeaders, Methods9['get']['status']>(prefix, prefix1, GET, option).json(),
/**
* @returns successful operation
*/
$get: (option?: { config?: T | undefined } | undefined) =>
fetch<Methods9['get']['resBody'], BasicHeaders, Methods9['get']['status']>(prefix, prefix1, GET, option).json().then(r => r.body),
/**
* This can only be done by the logged in user.
* @param option.body - Update an existent user in the store
*/
put: (option: { body: Methods9['put']['reqBody'], config?: T | undefined }) =>
fetch(prefix, prefix1, PUT, option, 'URLSearchParams').send(),
/**
* This can only be done by the logged in user.
* @param option.body - Update an existent user in the store
*/
$put: (option: { body: Methods9['put']['reqBody'], config?: T | undefined }) =>
fetch(prefix, prefix1, PUT, option, 'URLSearchParams').send().then(r => r.body),
/**
* This can only be done by the logged in user.
*/
delete: (option?: { config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, DELETE, option).send(),
/**
* This can only be done by the logged in user.
*/
$delete: (option?: { config?: T | undefined } | undefined) =>
fetch(prefix, prefix1, DELETE, option).send().then(r => r.body),
$path: () => `${prefix}${prefix1}`,
};
},
createWithList: {
/**
* Creates list of users with given input array
* @returns Successful operation
*/
post: (option: { body: Methods10['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods10['post']['resBody'], BasicHeaders, Methods10['post']['status']>(prefix, PATH7, POST, option).json(),
/**
* Creates list of users with given input array
* @returns Successful operation
*/
$post: (option: { body: Methods10['post']['reqBody'], config?: T | undefined }) =>
fetch<Methods10['post']['resBody'], BasicHeaders, Methods10['post']['status']>(prefix, PATH7, POST, option).json().then(r => r.body),
$path: () => `${prefix}${PATH7}`,
},
login: {
/**
* @returns successful operation
*/
get: (option?: { query?: Methods11['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods11['get']['resBody'], Methods11['get']['resHeaders'], Methods11['get']['status']>(prefix, PATH8, GET, option).text(),
/**
* @returns successful operation
*/
$get: (option?: { query?: Methods11['get']['query'] | undefined, config?: T | undefined } | undefined) =>
fetch<Methods11['get']['resBody'], Methods11['get']['resHeaders'], Methods11['get']['status']>(prefix, PATH8, GET, option).text().then(r => r.body),
$path: (option?: { method?: 'get' | undefined; query: Methods11['get']['query'] } | undefined) =>
`${prefix}${PATH8}${option && option.query ? `?${dataToURLString(option.query)}` : ''}`,
},
/**
* This can only be done by the logged in user.
* @param option.body - Created user object
*/
post: (option: { body: Methods8['post']['reqBody'], config?: T | undefined }) =>
fetch(prefix, PATH6, POST, option, 'URLSearchParams').send(),
/**
* This can only be done by the logged in user.
* @param option.body - Created user object
*/
$post: (option: { body: Methods8['post']['reqBody'], config?: T | undefined }) =>
fetch(prefix, PATH6, POST, option, 'URLSearchParams').send().then(r => r.body),
$path: () => `${prefix}${PATH6}`,
},
};
};
export type ApiInstance = ReturnType<typeof api>;
export default api;
</details>
- APIリクエストの[コード例](https://github.com/aspida/aspida#make-http-request-from-application)
- 課題
- 型生成単体として扱えるかどうか
- BE観点で扱いやすいかどうか
- aspidaに依存するような場合、微妙か
- まとめ
- openapi-typescriptとorvalの中間くらいのイメージ
- リンク
- [https://github.com/aspida/aspida](https://github.com/aspida/aspida)
- [https://github.com/aspida/openapi2aspida](https://github.com/aspida/openapi2aspida)