yapi-ts-builder
Version:
基于 yapi-to-typescript 实现的 YApi 接口定义生成工具
87 lines (86 loc) • 3.8 kB
TypeScript
/// <reference types="lodash" />
import { JSONSchema4, JSONSchema4TypeName } from 'json-schema';
import prettier from 'prettier';
import { OneOrMore } from 'vtils/types';
import { Interface, Method, PropDefinitions } from './types';
/**
* 抛出错误。
*
* @param msg 错误信息
*/
export declare function throwError(...msg: string[]): never;
/**
* 原地遍历 JSONSchema。
*/
export declare function traverseJsonSchema(jsonSchema: JSONSchema4, cb: (jsonSchema: JSONSchema4, currentPath: Array<string | number>) => JSONSchema4, currentPath?: Array<string | number>): JSONSchema4;
/**
* 原地处理 JSONSchema。
*
* @param jsonSchema 待处理的 JSONSchema
* @returns 处理后的 JSONSchema
*/
export declare function processJsonSchema(jsonSchema: JSONSchema4, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/**
* 将路径统一为 unix 风格的路径。
*
* @param path 路径
* @returns unix 风格的路径
*/
export declare function toUnixPath(path: string): string;
/**
* 获取适用于 JSTT 的 JSONSchema。
*
* @param jsonSchema 待处理的 JSONSchema
* @returns 适用于 JSTT 的 JSONSchema
*/
export declare function jsonSchemaToJSTTJsonSchema(jsonSchema: JSONSchema4, typeName: string): JSONSchema4;
/**
* 将 JSONSchema 字符串转为 JSONSchema 对象。
*
* @param str 要转换的 JSONSchema 字符串
* @returns 转换后的 JSONSchema 对象
*/
export declare function jsonSchemaStringToJsonSchema(str: string, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/**
* 获得 JSON 数据的 JSONSchema 对象。
*
* @param json JSON 数据
* @returns JSONSchema 对象
*/
export declare function jsonToJsonSchema(json: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/**
* 获得 mockjs 模板的 JSONSchema 对象。
*
* @param template mockjs 模板
* @returns JSONSchema 对象
*/
export declare function mockjsTemplateToJsonSchema(template: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/**
* 获得属性定义列表的 JSONSchema 对象。
*
* @param propDefinitions 属性定义列表
* @returns JSONSchema 对象
*/
export declare function propDefinitionsToJsonSchema(propDefinitions: PropDefinitions, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/**
* 根据 JSONSchema 对象生产 TypeScript 类型定义。
*
* @param jsonSchema JSONSchema 对象
* @param typeName 类型名称
* @returns TypeScript 类型定义
*/
export declare function jsonSchemaToType(jsonSchema: JSONSchema4, typeName: string, usedTypeNames?: Record<string, boolean>): Promise<string>;
/** 没有读懂 */
export declare function getRequestDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
/** 没有读懂 */
export declare function getResponseDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>, dataKey?: OneOrMore<string>): JSONSchema4;
export declare function reachJsonSchema(jsonSchema: JSONSchema4, path: OneOrMore<string>): JSONSchema4;
export declare function sortByWeights<T extends {
weights: number[];
}>(list: T[]): T[];
export declare function isGetLikeMethod(method: Method): boolean;
export declare function isPostLikeMethod(method: Method): boolean;
export declare function getPrettier(cwd: string): Promise<typeof prettier>;
export declare function getPrettierOptions(): Promise<prettier.Options>;
export declare const getCachedPrettierOptions: typeof getPrettierOptions & import("lodash").MemoizedFunction;
export declare function httpGet<T>(url: string, query?: Record<string, any>): Promise<T>;