UNPKG

yapi-ts-builder

Version:

基于 yapi-to-typescript 实现的 YApi 接口定义生成工具

51 lines (50 loc) 1.96 kB
/// <reference types="lodash" /> import { OmitStrict } from 'vtils/types'; import { Category, CategoryList, Config, Interface, InterfaceList, Project, SyntheticalConfig } from './types'; interface OutputFileList { [outputFilePath: string]: { _category: OmitStrict<Category, 'list'>; content: string[]; }; } export declare class Generator { private options; /** 配置 */ private config; private disposes; constructor(config: Config, options?: { cwd: string; }); prepare(): Promise<void>; generate(): Promise<OutputFileList>; write(outputFileList: OutputFileList): Promise<void[]>; fetchApi<T = any>(url: string, query: Record<string, any>): Promise<T>; fetchProject: (({ serverUrl, token }: SyntheticalConfig) => Promise<Project>) & import("lodash").MemoizedFunction; fetchExport: (({ serverUrl, token }: SyntheticalConfig) => Promise<Category[]>) & import("lodash").MemoizedFunction; /** 获取分类的接口列表 */ fetchInterfaceList({ serverUrl, token, id, }: SyntheticalConfig): Promise<InterfaceList>; /** 获取项目信息 */ fetchProjectInfo(syntheticalConfig: SyntheticalConfig): Promise<{ cats: CategoryList; getMockUrl: () => string; getDevUrl: (devEnvName: string) => string; getProdUrl: (prodEnvName: string) => string; _id: number; _url: string; name: string; desc: string; basepath: string; tag: string[]; env: { name: string; domain: string; }[]; }>; /** 生成单个api的ts代码 */ generateInterfaceCode(syntheticalConfig: SyntheticalConfig, // 综合配置参数 interfaceInfo: Interface, // 接口信息 categoryUID: string, // 分类唯一标识 usedTypeNames?: Record<string, boolean>): Promise<string>; destroy(): Promise<any[]>; } export {};