Socket
Book a DemoInstallSign in
Socket

icinfo-api-generator-test

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icinfo-api-generator-test

解析后端的微服务api文档,自动生成所需要的接口函数(TS格式的)

1.1.1
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

api自动化生成代码工具

解析后端的微服务api文档,自动生成所需要的接口函数(TS格式的)

引入的命令

npm i icinfo-api-generator

基本用法案例

在需要的项目中创建一个文件,比如 api.js

const axios = require('axios')
const { generate } = require('icinfo-api-generator')

async function main() {
    const apis = [
        'http://api.fed.icinfo.co/zzk/dtcenter/dt-qualities/develop/api.json',
    ]
    apis.forEach(async url => {
        const result = await axios(url)

        generate(result.data, {
            // mockDir: 'src/mock/data',
            tsDir: 'src/services',
            merge: true,
            request: 'http.request',
            prepend: `
import { ExAxiosRequestConfig } from 'icinfo-request'
import http from "@/scripts/http"`,
            optionsType: 'ExAxiosRequestConfig',
            dataDescription: '要提交给服务器的数据',
            optionsDescription: '附加选项',
            newLine: '\n',
        })

        // eslint-disable-next-line no-console
        console.log('已成功生成:', url.replace(/\/api\.json$/, ''))
    })
}

main()

同时在package.json配置scripts

"api": "node api.js"

执行方法为

npm run api

可配置的参数

名称类型是否必填说明默认值备注
getMockDatafunction自定义个别字段的模拟数据--
mockCountfunction自定义个别字段的模拟个数--
mockDirstring模拟数据文件夹地址--
mergeboolean是否合并已有的模拟数据--
mockDepthnumber嵌套对象的最多模拟次数--
mockPrefixstring模拟数据的前缀--
tsDirstring接口文件夹地址--
docFilestring生成的文档文件名--
prependstring模块前追加的内容--
optionsTypestring选项的类型--
dataDescriptionstring数据的描述--
optionsDescriptionstring附加选项的描述--
requeststring发起请求接口名--
newLinestring使用的换行符--
apiType'jquery'|'axios'参数配置的类型, 默认为jquery.ajax的方案,可选axios方案'jquery'-
scriptType'ts'|'js'脚本类型,默认生成ts类型,可选js类型'ts'-
includestring[]只有名称匹配的api全路径才会被生成--

FAQs

Package last updated on 19 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.