Class default<T>

Easy rest api helper

Type Parameters

Constructors

Properties

apiInfo: IApiInfo<T>
app: any
config: IAPIConfig
defineAPI: ((options, group?, prefix?) => default<T>)

Type declaration

    • (options, group?, prefix?): default<T>
    • Parameters

      • options: APIDefine<T>
      • Optional group: string
      • Optional prefix: string

      Returns default<T>

docsOptions: IDocOptions
error: {
    internalError: ((msg) => Error);
    invalidParameter: ((msg) => Error);
    missingParameter: ((msg) => Error);
}

Type declaration

  • internalError: ((msg) => Error)
      • (msg): Error
      • Parameters

        • msg: string

        Returns Error

  • invalidParameter: ((msg) => Error)
      • (msg): Error
      • Parameters

        • msg: string

        Returns Error

  • missingParameter: ((msg) => Error)
      • (msg): Error
      • Parameters

        • msg: string

        Returns Error

errorManage: ErrorManager
forceGroup: boolean
groupInfo: Record<string, IGroupInfo<T>>
groups: Record<string, string>
mockHandler?: ((data) => T)

Type declaration

    • (data): T
    • Parameters

      • data: any

      Returns T

registAPI: ((method, path, group?, prefix?) => default<T>)

Type declaration

    • (method, path, group?, prefix?): default<T>
    • Parameters

      • method: "delete" | "get" | "patch" | "post" | "put"
      • path: string
      • Optional group: string
      • Optional prefix: string

      Returns default<T>

schemaManage: SchemaManager = ...
shareTestData?: any
testAgent: default = ...
typeManage: ValueTypeManager = ...
utils: __module = utils

Accessors

  • get privateInfo(): {
        app: any;
        docsOptions: IDocOptions;
        error: {
            internalError: ((msg) => Error);
            invalidParameter: ((msg) => Error);
            missingParameter: ((msg) => Error);
        };
        groupInfo: Record<string, IGroupInfo<T>>;
        groups: Record<string, string>;
        info: IApiOptionInfo;
        mockHandler: undefined | ((data) => T);
    }
  • 获取私有变量信息

    Returns {
        app: any;
        docsOptions: IDocOptions;
        error: {
            internalError: ((msg) => Error);
            invalidParameter: ((msg) => Error);
            missingParameter: ((msg) => Error);
        };
        groupInfo: Record<string, IGroupInfo<T>>;
        groups: Record<string, string>;
        info: IApiOptionInfo;
        mockHandler: undefined | ((data) => T);
    }

    • app: any
    • docsOptions: IDocOptions
    • error: {
          internalError: ((msg) => Error);
          invalidParameter: ((msg) => Error);
          missingParameter: ((msg) => Error);
      }
      • internalError: ((msg) => Error)
          • (msg): Error
          • Parameters

            • msg: string

            Returns Error

      • invalidParameter: ((msg) => Error)
          • (msg): Error
          • Parameters

            • msg: string

            Returns Error

      • missingParameter: ((msg) => Error)
          • (msg): Error
          • Parameters

            • msg: string

            Returns Error

    • groupInfo: Record<string, IGroupInfo<T>>
    • groups: Record<string, string>
    • info: IApiOptionInfo
    • mockHandler: undefined | ((data) => T)

Methods

  • 注册文档生成组件

    Parameters

    • name: string
    • plugin: IDocGeneratePlugin

    Returns void

  • 获取Schema检查实例

    Returns ((schema, params?, query?, body?) => Record<string, any>)

      • (schema, params?, query?, body?): Record<string, any>
      • Parameters

        • schema: default<any>
        • Optional params: Record<string, any>
        • Optional query: Record<string, any>
        • Optional body: Record<string, any>

        Returns Record<string, any>

  • 绑定路由 (加载顺序:beforeHooks -> apiCheckParams -> middlewares -> handler -> afterHooks )

    Parameters

    • router: any

      路由

    • checker: ((ctx, schema) => T)
        • (ctx, schema): T
        • Parameters

          Returns T

    Returns void

  • 绑定路由到Express

    Parameters

    • app: any

      Express App 实例

    • Router: any

      Router 对象

    • checker: ((ctx, schema) => T)
        • (ctx, schema): T
        • Parameters

          Returns T

    Returns void

  • Type Parameters

    • U

    • V

    • W

    Parameters

    Returns ((req, res, next) => void)

      • (req, res, next): void
      • Parameters

        • req: U
        • res: V
        • next: W

        Returns void

  • 生成文档

    Parameters

    • savePath: string = ...

      文档保存路径

    • onExit: boolean = true

      是否等待程序退出再保存

    Returns void

  • 初始化测试系统

    Parameters

    • app: any

      APP或者serve实例,用于init supertest

    • testPath: string = ...

      测试文件路径

    • docPath: string = ...

      输出文件路径

    Returns void

  • 获取参数检查实例

    Returns ((name, value, schema) => any)

      • (name, value, schema): any
      • Parameters

        • name: string
        • value: any
        • schema: ISchemaType

        Returns any

  • 获取Schema检查实例

    Returns ((data, schema, requiredOneOf?) => any)

      • (data, schema, requiredOneOf?): any
      • Parameters

        • data: any
        • schema: Record<string, ISchemaType>
        • requiredOneOf: string[] = []

        Returns any

  • 设置文档格式化函数

    Parameters

    • fn: ((out) => any)
        • (out): any
        • Parameters

          • out: any

          Returns any

    Returns void

  • 设置文档格式化函数

    Parameters

    • fn: IDocWritter

    Returns void

  • 设置测试格式化函数

    Parameters

    • fn: ((out) => [null | Error, any])
        • (out): [null | Error, any]
        • Parameters

          • out: any

          Returns [null | Error, any]

    Returns void

  • Parameters

    • fn: ((data) => T)
        • (data): T
        • Parameters

          • data: any

          Returns T

    Returns void

Generated using TypeDoc