2.1.1 • Published 4 months ago

auto-request v2.1.1

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

简介

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

yapi的 swagger 可能会出现不兼容

配置 scripts

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

脚本

// apiPath(必填) api生成文件
// filename(必填) swagger schema 文件
// snapshotsPath(建议填写) = 增删文件日志,针对最终生成代码
// isTypeScript 是否ts模式
// loggerPath = 检查schema数据日志文件位置,针对schema文件
// logs 日志文件路径
// loggerFileName = 检查schema数据日志日志文件名
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',
  snapshotsPath: './snapshots.md'
  // renderMethodCall() {
  //   const args = renderMethodArgs([
  //       this.getMethodPrePath(),
  //       this.getMethodPreParams(),
  //       this.renderGetMethodData(),
  //       this.getMethodOption(),
  //     ]);
  //     const requestArgs = renderMethodArgs([
  //       `url: \`${this.getUrl()}\``,
  //       `method: \'${this.method}\'`,
  //       `${this.renderOptionsStr.data}`,
  //       `${this.renderOptionsStr.params}`,
  //       `...options`,
  //     ]);
  //     return `
  //     /***
  //            * @description  ${this.description}
  //            **/
  //           export const ${this.getMethodsName()} = ( ${args} ) => {
  //               return axios.request({${requestArgs}})
  //           }\n
  //     `;
  // },
  // renderHeaderTemplate: (instance) => {

  // }
}).then(({ write, json }: any) => {
  write();
}).catch((err) => {
  console.log(err)
});

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

生成目录

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

生成文件

import axios, { value AxiosRequestConfig, value 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.1.1

4 months ago

2.0.13

4 months ago

2.0.5

4 months ago

2.0.11

4 months ago

2.0.12

4 months ago

2.1.0

4 months ago

2.0.9

9 months ago

2.0.10

9 months ago

2.0.7

1 year ago

2.0.8

1 year ago

2.0.3

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

1.1.5

2 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.0

3 years ago