npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto-request

v2.0.10

Published

通过Yapi JSON Schema生成接口Axios或Taro接口

Downloads

17

Readme

简介

通过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',
  // 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();
});

生成的文件 接口文件: {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;
}