UNPKG

fastman

Version:

快速api测试及文档生成

130 lines (108 loc) 3.2 kB
import {OpenApi3} from "./spec/openapi-3"; import {Swagger} from "./spec/openapi-2"; import Spec from "./spec/base"; import {Postman} from "./postman"; import {Promise} from "es6-promise"; export declare type Resource = OpenApi3.PathItemObject | Swagger.Path | any; export declare type Info = OpenApi3.InfoObject | Swagger.Info | any; export declare type Operation = OpenApi3.OperationObject | Swagger.Operation | any; export declare type SecurityScheme = OpenApi3.SecuritySchemeObject | Swagger.Security | any; export declare type Server = OpenApi3.ServerObject | Swagger.Server | any; export declare type Response = OpenApi3.ResponseObject | Swagger.Response | any; export declare type Component = OpenApi3.Component | Swagger.Schema | any; export declare type Example = OpenApi3.ExampleObject | Swagger.Example | any; export interface TestCase { name: string; request?: Postman.Request; response?: Postman.Response; save?: boolean; saveRequest?: boolean; excludePostman?: boolean; params?: string[]; query?: object; body?: object; header?: Postman.Header[]; } export interface GlobalHeader { all?: object; get?: object; post?: object; put?: object; delete?: object; head?: object; patch?: object; } export declare function getComponentRef(name: string, type?: string): string; export default class Fastman { private state; private spceVersion; spec: Spec; private runner?; /** * 指定使用openapi版本 * @param {number} version */ openApiVersion(version: number): Fastman; /** * 将openapi文档写入字符串 * @returns {string} */ writeSpec(): string; /** * 设置openapi的info */ info(info: Info): Fastman; component(name: string, value: Component, type?: string): this; /** * 从给定字符串或object中读取 文档 * @param {string | object} spec * @returns {this} */ load(spec: string | object): this; response(status: any, response?: Response): this; /** * 选择或新建一个资源 * @param name 资源名称 */ resource(name: string): this; /** * 选择或新建一个路径 * @param {string} path */ path(path: string): this; /** * 设置全局的headers * @param {object} headers */ globalHeaders(headers: GlobalHeader): this; /** * 配置Server * @param {Server} server */ server(server: Server): this; /** * 选择或新建一个操作 * @param {string} method * @param operation */ operation(method: string, operation?: Operation): this; /** * 准备测试用例 */ testCase(testCase: TestCase): this; except(expect: any): this; private getCaseKey(name); /** * 导出postman 结果,将测试的结果保存在postman的collection文件中 * 如果给出的file不存在,则会新建一个collection文件 * 如果file存在,则会在collection中按照 resource 分文件夹存放测试用例 * * 同时,会自动将 host port bearer 等转换为postman的环境格式 * @param {string} file 保存文件的路径 */ exportPostman(file: string): void; /** * 测试 */ run(): Promise<any>; }