New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smart-api-generator

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-api-generator

smart-api-generator是一个高效能的工具,专门用来自动化创建API接口及其相关文档

  • 1.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

smart-api-generator

npm (scoped) Downloads Coverage Status

smart-api-generator是一个高效能的工具,专门用来自动化创建API接口及其相关文档

功能点

  • 以项目维度生成格式统一的接口配置,可直接用于生产环境中
  • 良好的入参、出参注释,可直接拷贝使用接口调用代码
  • 接口调用支持typescript智能提示与校验
  • 支持ts文件生成与接口结构interface的生成

安装

// npm
npm install smart-api-generator -D

// yarn
yarn add smart-api-generator -D

// pnpm
pnpm install smart-api-generator -D

使用步骤

1、在 package.json 中配置命令,配置文件可指定路径,如果不指定路径默认取根目录下的.api.config.js文件

"scripts": {
        ......
    "api": "cross-env smart-api create --config /path/to/.api.config.js"
},

2、在工程中添加配置文件·api.config.js

module.exports = {
    output: './src/request',
    projects: [
        {
            projectName: 'xxx',
            basePath: 'xxx',
            //...
        }
    ]
}

3、在根目录中运行命令

npm run api

配置项

参数说明必填类型默认值版本
output接口文件输出目录truestring-1.0.0
hostswagger平台地址falsestringhttps://letao.cnstrong.cn1.0.0
projects接口文档配置truearray-1.0.0

projects

参数说明必填类型默认值版本
projectName项目名称,对应swagger接口文档地址,如:https://letao.cnstrong.cn/letao-official-document-center/doc.html#/home 中,projectName 为 letao-official-document-centertruestring-1.0.0
basePath接口统一前缀,默认会使用swagger文档中的basePath字段,如果文档与实际有差异,请手动配置falsestringswagger文档主页中的basePath字段1.0.0
comment是否需要生成注释falsebooleantrue1.0.0
folderName生成文件夹的名称falsestring默认使用 projectName1.0.0
tsNotStrictInclude生成的ts代码时,控制请求参数/返回结果是否严格模式,req 参数部分关闭严格模式,res 返回部分关闭严格模式 falsestring[]['res']1.1.0
extractResponseKeys对接口返回结构进行提取,应对axios拦截器对请求返回做提取的场景,如['data']则提取接口返回中的data字段作为Res,可以配置多个,返回匹配到的第一个falsestring[]-1.2.0
tags可以只生成项目下指定分类下的接口, 如: ['user']falsestring[]-1.2.0
extractAxiosPromise是否提取axios返回的data层级falseboolean-1.2.3
mergeConfig 打开,不会删除本地配置有但是接口文档中没有的接口,可以手动删除,而且新增的接口都会排列到最后面
关闭,文件的生成完全按照接口文档生成
trueboolean-1.3.0

Keywords

FAQs

Package last updated on 05 Aug 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc