0.1.4 • Published 4 years ago

gapi-tool v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

svgwave.in_ (1)

1. 介绍

通过后端生成的 api docs 自动生成前端接口调用函数(带 typescript 入参类型检查,接口返回值类型提示)

2. 配置 gapi.config.js

import { defineGapiConfig } from 'gapi-tool'
export default defineGapiConfig(() => {
  return {
    outDir: './api',
    restfulParamsInFn: false,
    originGroups: [
      {
        name: 'python',
        originUrl: 'http://localhost:3000/swagger-json',
        originType: 'openApiV2',
      },
      {
        name: 'java',
        originUrl: 'http://localhost:8080/swagger-json',
        originType: 'openApiV3',
      },
    ],
    prettierConfig: {
      semi: false,
      singleQuote: true,
      printWidth: 120,
      arrowParens: 'avoid',
      trailingComma: 'es5',
      endOfLine: 'crlf',
    },
    template: ({ url, method, apiName, typeImportStr, reqType, resType }) => {
      return `
        import { AxiosRequestConfig } from 'axios'
        import request from '@/utils/request'
        ${typeImportStr}

        export const ${apiName} = (data: ${reqType}, config?: AxiosRequestConfig): Promise<${resType}> =>{
            return request({
                url: ${url},
                method: '${method}',
                data,
                config
            })
        }`
    },
  }
})

3. 运行

package.json add scripts "gapi": "npx gapi-tool" then yarn gapi

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago