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

@xm-fe/create-api

Package Overview
Dependencies
Maintainers
7
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xm-fe/create-api

API快速导入

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-82.35%
Maintainers
7
Weekly downloads
 
Created
Source

⚡️ 简介

2022 鲜沐科技 前端通用逻辑包

🚀 使用

npm i @xm-fe/create-api -g

运行capi命令时,会读取当前项目根目下的的 capi.config.js文件,该文件中的配置会覆盖默认配置文件。

capi.config.js 具体配置及解释看文末

方式一

capi http://127.0.0.1:4523/export/openapi/9?version=3.0 954456

capi apifox导出的URL projectId

方式二

capi

读取项目根目录配置文件 capi.config 中的 remotePath

0.0.1

  • 初始化

🚀 开发


# 安装依赖
npm i
# 发布流程

# 编译
npm run build

# 本项目
npm link

# 引用调试的项目
npm link 包名

# 取消关联
npm unlink 包名

# 查看
npm ls -g

capi.config.js 配置

module.exports = {
  // 生成目录
  targetPath: `/src/apx`,
  truePath: `apis`,
  // targetTypePath: `/src/api-typess`,
  // 读本地文件生成
  useLocal: false,
  // 本地文件地址
  localPath: `./test3.0.1.json`,
  remotePath: `http://127.0.0.1:4523/export/openapi/6?projectId=2517920&version=3.0`,
  // 暂时搞不定的接口
  ignorePath: [
    // 响应值多层数组??
    // '/crm/detail/panic-buy/{pageIndex}/{pageSize}',
    // // body参数没有key??
  ],
  // 运行时会自动修改
  appName: 'main',
  // 从apifox生成的直接写死appName映射
  appNameMap: {
    '1164722': 'summerfarm-manage',
    '1409074': 'tms',
    '954456': 'cosfo',
    '2517920': 'rs'
  },
  // 路径参数别名
  paramsNumName: {
    0: '',
    1: 'Query',
    2: 'Double',
    3: 'Triple',
    4: 'Quatra',
    5: 'Penta'
  },
  listModel: {
    type: 'object',
    properties: {
      code: {
        type: 'string'
      },
      data: {
        type: 'object',
        properties: {
          endRow: {
            type: 'number'
          },
          firstPage: {
            type: 'number'
          },
          hasNextPage: {
            type: 'boolean'
          },
          hasPreviousPage: {
            type: 'boolean'
          },
          isFirstPage: {
            type: 'boolean'
          },
          isLastPage: {
            type: 'boolean'
          },
          lastPage: {
            type: 'number'
          },
          list: {
            type: 'array',
            items: {}
          },
          navigatePages: {
            type: 'number'
          },
          navigatepageNums: {
            type: 'array',
            items: {
              type: 'number'
            }
          },
          nextPage: {
            type: 'number'
          },
          pageNum: {
            type: 'number'
          },
          pageSize: {
            type: 'number'
          },
          pages: {
            type: 'number'
          },
          prePage: {
            type: 'number'
          },
          size: {
            type: 'number'
          },
          startRow: {
            type: 'number'
          },
          total: {
            type: 'number'
          }
        }
      },
      msg: {
        type: 'string'
      }
    }
  },
  // 插入的模板代码
  getApiCodeTpl(api) {
    const pathParams = api.pathParams
      .map((param) => `${param.name}${param.required ? '' : '?'}: ${param._type},`)
      .join('\r\n')
    return `
  import net from '@/utils/net'
  import { NetConfig } from '@/interface/IAxiosConfig'
  /**
   * ${api.summary}
   */
  export function ${api.name}(
    ${pathParams ? pathParams : ''}
    ${api.queryParams ? `params?: ${api.queryParams._name},` : ''}
    ${api.bodyParams ? `data?: ${api.bodyParams._name},` : ''}
    config?: NetConfig
  ): Promise<${api.resType}> {
    return net(
      {
        url: \`${api.url}\`,
        method: '${api.method}',
        ${api.isDownload ? `_download: true,` : ''}
        ${api.queryParams ? `params,` : ''}
        ${api.bodyParams ? ` data,` : ''}
      },
      config
    )
  }
  `
  }
}

Keywords

FAQs

Package last updated on 19 Jun 2023

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