auto-request
Version:
通过Yapi JSON Schema生成接口Axios或Taro接口
48 lines • 1.67 kB
TypeScript
/**
* Swagger 获取模块
* 支持多种方式获取 Swagger JSON
*/
import { AxiosInstance, AxiosRequestConfig } from 'axios';
/**
* Swagger 获取配置 - 通过 HTTP 请求获取
*/
export interface SwaggerHttpConfig {
url: string;
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
headers?: Record<string, string>;
params?: Record<string, any>;
data?: any;
timeout?: number;
axiosConfig?: AxiosRequestConfig;
}
/**
* Swagger 获取函数类型
* @param axios - Axios 实例,用户可以使用这个实例发起请求
* @returns Promise<string> - 返回 Swagger JSON 字符串
*/
export type SwaggerFetcherFunction = (axios: AxiosInstance) => Promise<string>;
/**
* Swagger 数据源类型
* - string: 直接传入 Swagger JSON 字符串
* - SwaggerHttpConfig: HTTP 请求配置
* - SwaggerFetcherFunction: 自定义获取函数
*/
export type SwaggerSource = string | SwaggerHttpConfig | SwaggerFetcherFunction;
/**
* 获取 Swagger JSON
* @param source - Swagger 数据源(字符串、HTTP 配置或自定义函数)
* @returns Promise<string> - Swagger JSON 字符串
*/
export declare const fetchSwagger: (source: SwaggerSource) => Promise<string>;
/**
* 验证 Swagger JSON 是否有效
*/
export declare const validateSwagger: (swaggerJson: string) => boolean;
/**
* 保存 Swagger 备份文件
* @param swaggerJson - Swagger JSON 字符串
* @param backupPath - 备份文件路径,支持 {timestamp} 占位符(可选)
* @returns 实际保存的文件路径
*/
export declare const saveSwaggerBackup: (swaggerJson: string, backupPath: string) => string;
//# sourceMappingURL=swagger-fetcher.d.ts.map