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

api-generator-ci

v1.0.5

Published

根据接口文档自动生成类型文件以及接口方法

Downloads

3

Readme

介绍

根据openapi swagger两种数据格式json生成相应的接口以及数据类型,

安装

    npm i api-generator-ci
api-build [options]
Options:
  -c --configpath        //文件路径
  -i                  //是否根据选择导出.是

cli 使用

api-build -c ./apiBuildConfig.js -i

::: TIP -c : 设定配置文件所在地址,不传则默认取终端当前目录下的 apiBuildConfig.js :::

参数详细说明

interface Options {
    /**
     * swagger / openapi json
     */
    api: string

    /**
     * 名字空间
     */
    namespace: string

    /**
     * 输出目录,绝对地址
     */
    sdkDir: string

    /**
     * 过滤数据
     */
    filter?: Array<(api: APIDataType, tag?: string) => boolean>

    /**
     * 完成后执行
     */
    done?: Function
}

文件配置

// config.js
const { defineConfigs } = require('api-generator-ci')
const path = require('path')

module.exports = defineConfigs([
    {
        //json数据路径 可以为url也可以为json文件
        api: 'http://127.0.0.1:4523/export/openapi/6',
        //生成文件目录
        sdkDir: path.join(__dirname, './temp/i/api/strapi'),
        //数据类型命名空间
        namespace: 'ApiStrapi',
        //过滤文档某些不需要用的又没删除接口
        filter: [
            (api) => {
                const liteApis = ['/user/uerInfo/{id}']
                if (liteApis.includes(api.path)) return true
                return false
            },
        ],
    },
])

//输出列子

//intex.ts

/**
 * ------------------------------------
 * !!! 不要修改,这是生成的代码 !!!
 * ------------------------------------
 */
import * as test from './test'

export { test }

//test.ts 此文件为接口组名我自己定义的

// @ts-nocheck

/**
 * ------------------------------------
 * !!! 不要修改,这是生成的代码 !!!
 * ------------------------------------
 */
import request from '../request'

type Options = Parameters<typeof request>['1']

/**
 * first_test * */
export function userInfoId(
    paths: ApiStrapi.ParamUserUserInfoid,
    data: ApiStrapi.ReqUserUserInfoid,
    options: Options = {}
) {
    const headers = { 'content-type': 'application/json' }

    const url = '/user/userInfo/{id}'.replace('{id}', String(paths['id']))
    return request<ApiStrapi.ResUserUserInfoid>(
        url,
        {
            method: 'GET',
            data,
            apiPath: '/user/userInfo/{id}',
            ...options,
            headers: {
                ...headers,
                ...(options.headers || {}),
            },
        },
        'ApiStrapi'
    )
}

//typings.d.ts

/**
 * ------------------------------------
 * !!! 不要修改,这是生成的代码 !!!
 * ------------------------------------
 */
// tslint:disable
declare namespace ApiStrapi {
    export interface ResUserUserInfoid {
        /**
         * 状态码
         */
        code: number
        /**
         * 提示信息
         */
        msg: string
        data: ResUserUserInfoidData
    }
    /**
     * 数据
     */
    export interface ResUserUserInfoidData {
        /**
         * 用户名
         */
        user_name: string
        /**
         * 唯一标识
         */
        id: string
        /**
         * 电话号码
         */
        phone: string
        info: ResUserUserInfoidDataInfo
    }
    /**
     * 具体信息
     */
    export interface ResUserUserInfoidDataInfo {
        /**
         * 地址
         */
        address: string
    }

    export interface ParamUserUserInfoid {
        id: string
    }

    export interface ReqUserUserInfoid {}
}