UNPKG

openapi-ts-request

Version:

Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas

76 lines (75 loc) 4.36 kB
import type { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaObject, NonArraySchemaObject, OpenAPIObject, OperationObject, ReferenceObject, SchemaObject } from '../type'; import type { ITypeItem } from './type'; /** * 汉字转连续无音调小写拼音(对齐原 tiny-pinyin 的 convertToPinyin(str, '', true)) */ export declare function toPlainPinyin(str: string): string; export declare function stripDot(str: string): string; export declare function resolveTypeName(typeName: string): string; export declare function getRefName(refObject: ReferenceObject | string): string; /** * 获取引用类型名称,支持类型名称映射 * @param refObject 引用对象 * @param schemaKeyToTypeNameMap 从原始 schema key 到最终类型名称的映射(处理重名情况) * @returns 最终的类型名称 */ export declare function getRefNameWithMapping(refObject: ReferenceObject | string, schemaKeyToTypeNameMap?: Map<string, string>): string; export declare function getLastRefName(refPath?: string): string; export declare function getDefaultType(schemaObject?: ISchemaObject | string, namespace?: string, schemas?: ComponentsObject['schemas'], schemaKeyToTypeNameMap?: Map<string, string>): string; export declare function getDefaultFileTag(operationObject: OperationObject, apiPath: string): string[]; export declare function handleDuplicateTypeNames(interfaceTPConfigs: Array<Pick<ITypeItem, 'typeName' | 'displayLabelFuncName' | 'originalSchemaKey'>>): Map<string, string>; export declare function getBasePrefix(paths: string[]): string; export declare function genDefaultFunctionName(path: string, pathBasePrefix: string): string; export declare function getFinalFileName(s: string): string; export declare function replaceDot(s: string): string; export declare function resolveFunctionName(functionName: string, methodName: string): string; export declare function markAllowedSchema(schemaStr: string, openAPIData: OpenAPIObject): void; export declare function isReferenceObject(schema: unknown): schema is ReferenceObject; export declare function isSchemaObject(schema: unknown): schema is SchemaObject; export declare function isNonArraySchemaObject(schema: unknown): schema is NonArraySchemaObject; export declare function isArraySchemaObject(schema: unknown): schema is ArraySchemaObject; export declare function isBinaryArraySchemaObject(schema: unknown): schema is BinaryArraySchemaObject; export declare function resolveRefs(obj: OpenAPIObject, fields: string[]): unknown; export declare function isAllNumeric(arr: any): boolean; export declare function isAllNumber(arr: any): boolean; export declare function capitalizeFirstLetter(str: string): string; /** * 转义字符串,用于 JavaScript 字符串字面量 * 将换行符、单引号等特殊字符转义为转义序列 */ export declare function escapeStringForJs(str: string): string; export declare const parseDescriptionEnum: (description: string) => Map<number, string>; /** * 通过自定义正则表达式解析 description 中的枚举翻译 * @param description 描述文本 * @param regex 自定义正则表达式,用于匹配枚举项,例如:(\S+)\s*=\s*(\S+) * @returns Map<number, string> 枚举值到标签的映射 */ export declare const parseDescriptionEnumByReg: (description: string, regex: string | RegExp) => Map<number, string>; /** * 获取默认的二进制媒体类型列表 */ export declare const getDefaultBinaryMediaTypes: () => string[]; /** * 获取二进制媒体类型列表 * 支持配置自定义二进制媒体类型 * @param customBinaryTypes 自定义二进制媒体类型列表 */ export declare const getBinaryMediaTypes: (customBinaryTypes?: string[]) => string[]; /** * 检测是否为二进制媒体类型 * @param mediaType 媒体类型 * @param binaryMediaTypes 二进制媒体类型列表 */ export declare const isBinaryMediaType: (mediaType: string, binaryMediaTypes: string[]) => boolean; /** * 获取二进制响应类型 * 默认返回 Blob,这是浏览器环境中最常用的二进制类型 */ export declare const getBinaryResponseType: () => string; /** * 获取 axios responseType 配置 * 根据二进制响应类型返回对应的 responseType * @param binaryType 二进制类型 */ export declare const getAxiosResponseType: (binaryType: string) => string;