2.0.8 • Published 2 months ago

auto-request v2.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

简介

通过yapi的 swagger json schema 生成 Taro 或 Axios 接口

yapi的 swagger 可能会出现不兼容

配置 scripts

    "scripts": {
        "build:api": "node ./scripts/buildApi.js"
    },

脚本

// apiPath(必填) api生成文件
// filename(必填) swagger schema 文件
// isTypeScript 是否ts模式
// loggerPath = 日志文件位置
// logs 日志文件路径
// loggerFileName = 日志文件名
import { autoRequest } from '../dist/bundle';
import path from 'path';
import allApi from './../example/all-api.json';
const apiPath = path.join(__dirname, './../api/');
const logs = path.join(__dirname, './../logs/');
autoRequest(JSON.stringify(allApi) as any, apiPath, {
  filename: 'all-api',
  isTypeScript: true,
  loggerPath: logs,
  loggerFileName: 'all-api.json',
}).then(({ write, json }: any) => {
  write();
});

生成的文件 接口文件: {path}/index.ts 定义文件: {path}/index.define.ts

生成目录

    ├── api
    │   ├── index.define.ts
    │   └── index.ts
    ├── assets
    │   └── api.json
    |── scripts
    |    └── buildApi.js
    |

生成文件

import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';

/***
 * @description  获取实例的告警历史
 **/
export const AlertalertHistoryGet = <
  S = AxiosResponse<AlertalertHistoryGetResponse>
>(
  options: AxiosRequestConfig = {}
): Promise<S> => {
  return axios.request({
    url: `/alert/alert_history`,
    method: 'get',
    ...options,
  });
};
// index.define.ts
* tslint:disable */
/**
 * This file was automatically generated by json-schema-to-typescript.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
 * and run json-schema-to-typescript to regenerate this file.
 */

export interface AlertalertInstanceGetRequsetParams {
  /**
   * page
   */
  page: number;
  /**
   * page_size
   */
  page_size: number;
  /**
   * 1.开始时间升序;2.告警次数升序;5.开始时间倒序;6.告警次数倒序
   */
  order: number;
  /**
   * (多个)严重程度
   */
  severity_list?: string;
  /**
   * (多个)firing:正在告警,normal:正常 用逗号间隔
   */
  status_list: string;
  /**
   * (多个)团队id,不传查全部
   */
  team_ids?: number;
  /**
   * (多个)负责人id,不查传全部
   */
  duty_user_list?: number;
  /**
   * (多个)规则来源模块,不查传全部
   */
  from_sre_list?: string;
  /**
   * 分组条件(单个): 1.Sre模块 2.规则 3.负责人 4.团队 5.业务实例
   */
  group_by?: number;
  /**
   * (多个)处理状态。如果不传,默认不包含失效的。0.未处理1.已确认2.维护3.失效
   */
  handle_status_list?: number;
}
export interface AlertalertInstanceGetResponse {
  groups?: AlertalertInstanceGetResponseGroups[];
  page?: AlertalertInstanceGetResponsePage;
}
2.0.7

2 months ago

2.0.8

2 months ago

2.0.3

6 months ago

2.0.4

6 months ago

2.0.1

8 months ago

1.1.5

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago