openapi-axios
Version:
OpenAPI(2.0/3.0/3.1) Schema → Type-safe Axios
58 lines (57 loc) • 1.7 kB
TypeScript
import { Options } from 'prettier';
import { EventMap } from 'strict-event-emitter';
import { PrinterOptions } from '../printer/types';
import { OpenAPILatest } from '../types/openapi';
type RequiredWith<T, K extends keyof T> = T & {
[P in K]-?: T[P];
};
export type OpenAPIOptions = PrinterOptions & {
/**
* 文件名称
* @default ${module}.ts
*/
fileName?: string;
/**
* openapi 的 document,可以是一个链接地址,也可以是本地路径,也可以是一个对象
*/
document: OpenAPILatest.Document | string;
};
export type GeneratorOptions = PrinterOptions & {
/**
* 工作目录,默认为 process.cwd()
*/
cwd?: string;
/**
* 生成文件目的地,默认为 src/apis
*/
dest?: string;
/**
* 格式化配置,默认会读取当前工作目录下的配置文件
*/
prettierOptions?: Options;
/**
* openapi 文档配置
*/
documents: Record<string, OpenAPIOptions | string>;
};
export type StrictGeneratorOptions = RequiredWith<GeneratorOptions, 'cwd' | 'dest'>;
export type GeneratingStage = 'reading' | 'printing' | 'writing' | 'generated';
export type GeneratingOptions = OpenAPIOptions & Pick<StrictGeneratorOptions, 'cwd' | 'dest'>;
export interface GeneratorPayload {
count: number;
}
export interface GeneratingPayload {
index: number;
count: number;
name: string;
stage: GeneratingStage;
options: GeneratingOptions;
file: string;
}
export interface GeneratorEmits extends EventMap {
start: [GeneratorPayload];
end: [GeneratorPayload];
process: [GeneratingPayload];
error: [Error, GeneratorPayload];
}
export {};