/** * 主要实现流程: * 1. 生成共享对象生成公共类型 * 2. 递归处理 parameters 上的数据,主要包含 query 和 param(path 参数),生成类型,有公用类型则指向公用类型名称,否则生成类型字符串 * 3. 递归处理 request body 数据,生成类型,有公用类型则指向公用类型名称,否则生成类型字符串 * 4. 递归处理 response 数据,生成类型,有公用类型则指向公用类型名称,否则生成类型字符串 * 5. 遍历 paths 生成 api 描述数据数据 */ /** * * 遍历 paths 生成 api 描述数据数据 * get xx/1/2?a=1 1,2生成命名为Param结尾 a生成命名为Query结尾 */ import { API } from '../interface/common'; import { DefinitionsMetadata, Swagger2_Docs } from 'src/interface/swagger2/doc'; import { Options } from 'src/interface/config'; interface SourceInfo { /**文档一级目录名称 */ tags: string[]; /**接口描述名称 */ summary: string; /** 接口锚点定位参数 */ operationId: string; } type SchemaParserOptions = Options & { isoStringTypeName: string; }; export declare class SchemaParser { #private; /** 所有类型名字 -> 类型字符串 */ types: Record; /** 所有 api 列表 */ apis: API[]; constructor(docs: Swagger2_Docs, options: SchemaParserOptions); /** 创建 interface 字符串 */ private createInterfaceString; /** 生成带有继承关系的类型字符串 */ private createExtendsInterfaceString; /** 创建 type 类型个别名字符串 */ private createTypeAliasString; /** 将 api path 和 请求方式组合生成 api 名称 */ private mapApiPathToApiName; /** 过滤得到合法的 schema */ private getLegalSchema; /** * 根据schema生成数据type * @param interfaceName * @param fieldName * @param schema * @returns */ private getTypeNameFromSchema; private createInterfaceStringFormObjectSchema; /** 解析 components/schema 下的公共数据生成类型 */ private createCommonTypes; /** * query类型下path的parameters数据type处理方法 * type不是schema类型的 */ private getTypeNameFromServeType; /** get请求的 */ /** 解析 query 和 param 的类型 */ private createQueryAndParamTypes; /** 解析 body 类型 */ private createBodyTypes; /** 解析 response 类型 */ private createResponseTypes; /** * definitions 生成type * definitions 本身还会自循环, * 现阶段思路: * @param definitions * @param name interface 名称 * @param source { tags: string[]; summary: string,operationId:number }目录+接口描述 */ createTypesByDefinitions(definitions: DefinitionsMetadata, name: string, source: SourceInfo, definitionKey?: string): void; /** * * 现阶段思路,正则读取最内层的名称,作为response的interface; * 后期优化 TODO:如果层级过多时,就需要一层一层的匹配处理 * @param _refName definitions key or key[] * @param render 是否生成interface * @returns */ dealWithDefinitionSchema(_refName: string, source: SourceInfo, render?: boolean): string; /** * 获取内部定义名称 * eg:BaseApiResponse«TlSmoBiddingProgressInfoResponse» 得到:TlSmoBiddingProgressInfoResponse * @param name * @returns */ getArrowTypeName(name: string): string; /** 生成接口并添加到 this.APIList */ private createAPIs; /** 创建所有的类型相关信息 */ private main; /** 开始解析 */ parse(): void; } export {};