98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
/* tslint:disable */
|
|
/* eslint-disable */
|
|
/**
|
|
* 用户中心接口文档 - version 0.0.1-SNAPSHOT
|
|
*
|
|
* Demo project for Spring Boot
|
|
*
|
|
* OpenAPI version: 3.0.0
|
|
*
|
|
* Contact:
|
|
*
|
|
* NOTE: This file is auto generated by the alova's vscode plugin.
|
|
*
|
|
* https://alova.js.org/devtools/vscode
|
|
*
|
|
* **Do not edit the file manually.**
|
|
*/
|
|
import { Method } from 'alova';
|
|
import apiDefinitions from './apiDefinitions';
|
|
|
|
const cache = Object.create(null);
|
|
const createFunctionalProxy = (
|
|
array: (string | symbol)[],
|
|
alovaInstance: Alova<any, any, any, any, any>,
|
|
configMap: any
|
|
) => {
|
|
const apiPathKey = array.join('.') as keyof typeof apiDefinitions;
|
|
if (cache[apiPathKey]) {
|
|
return cache[apiPathKey];
|
|
}
|
|
// create a new proxy instance
|
|
const proxy = new Proxy(function () {}, {
|
|
get(_, property) {
|
|
// record the target property, so that it can get the completed accessing paths
|
|
const newArray = [...array, property];
|
|
// always return a new proxy to continue recording accessing paths.
|
|
return createFunctionalProxy(newArray, alovaInstance, configMap);
|
|
},
|
|
apply(_, __, [config]) {
|
|
const apiItem = apiDefinitions[apiPathKey];
|
|
if (!apiItem) {
|
|
throw new Error(`the api path of \`${apiPathKey}\` is not found`);
|
|
}
|
|
const mergedConfig = {
|
|
...configMap[apiPathKey],
|
|
...config
|
|
};
|
|
const [method, url] = apiItem;
|
|
const pathParams = mergedConfig.pathParams;
|
|
const urlReplaced = url!.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
const pathParam = pathParams[key];
|
|
return pathParam;
|
|
});
|
|
delete mergedConfig.pathParams;
|
|
let data = mergedConfig.data;
|
|
if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
let hasBlobData = false;
|
|
const formData = new FormData();
|
|
for (const key in data) {
|
|
if (Array.isArray(data[key])) {
|
|
for (const ele of data[key]) {
|
|
formData.append(key, ele);
|
|
if (ele instanceof Blob) {
|
|
hasBlobData = true;
|
|
}
|
|
}
|
|
} else {
|
|
formData.append(key, data[key]);
|
|
if (data[key] instanceof Blob) {
|
|
hasBlobData = true;
|
|
}
|
|
}
|
|
}
|
|
data = hasBlobData ? formData : data;
|
|
}
|
|
return new Method(method!.toUpperCase() as MethodType, alovaInstance, urlReplaced, mergedConfig, data);
|
|
}
|
|
});
|
|
cache[apiPathKey] = proxy;
|
|
return proxy;
|
|
};
|
|
|
|
export const createApis = (alovaInstance: Alova<any, any, any, any, any>, configMap: any) => {
|
|
const Apis = new Proxy({} as Apis, {
|
|
get(_, property) {
|
|
return createFunctionalProxy([property], alovaInstance, configMap);
|
|
}
|
|
});
|
|
return Apis;
|
|
};
|
|
|
|
export const mountApis = (Apis: Apis) => {
|
|
// define global variable `Apis`
|
|
(globalThis as any).Apis = Apis;
|
|
};
|
|
|
|
export const withConfigType = <Config extends MethodsConfigMap>(config: Config) => config;
|