大家写项目的时候联调对接后端,写相应的 API 函数的时候会不会觉得很麻烦,我是这么觉得的,如果使用的 Typescript ,确保和后端的类型保持一致,还要手写类型,接口请求和返回参数定义类型成了繁琐的一件事情。
如果后端有提供接口描述的数据源(swagger、yapi 或其他源)等等,我们就可以利用 aippgen 自动的生成接口与类型。
/**
* @summary uploads an image
* @method post
*/
export function postPetPetIdUploadImage(data: FormData, paths: OpenAPITypes.PostPetPetIdUploadImagePath, config?: AxiosRequestConfig) {
const url = `/pet/${
paths?.petId}/uploadImage`
http.request<Response<OpenAPITypes.ApiResponse>>({
url, data, ...config })
}
/**
* @summary Add a new pet to the store
* @method post
*/
export function postPet(data: OpenAPITypes.Pet, config?: AxiosRequestConfig) {
const url = '/pet'
http.request<Response<void>>({
url, data, ...config })
}
export type Response<T> = T;
export interface ApiResponse {
code?: number;
type?: string;
message?: string;
}
export interface Category {
id?: number;
name?: string;
}
export interface Pet {
id?: number