@pubinfo/openapi
TypeScript icon, indicating that this package has built-in type declarations

0.6.2 • Public • Published

@pubinfo/openapi

npm version Monorepo License

Generate request files according to the OpenAPI.

Usage

Need config file in your project root directory:

// openapi.config.js / openapi.config.ts
export default {
  /* options */
}

and then run:

npx @pubinfo/openapi@latest generate

Configuration

OpenAPI({
  // 是否启用,默认 true
  enabled: true,

  // 忽略缓存强制生成接口文件,默认 false
  force: false,

  // 文件默认导入
  imports: {
    '@/api': 'request', // import request from '@/api'
    'request': ['foo', 'bar'], // import { foo , bar } from 'request'
    'request': [{ name: 'foo', as: 'bar' }] // import { foo as bar } from 'request'
  },

  // Swagger2.0 / OpenAPI3.0 地址,直接指向JSON的地址
  input: 'http://your/api-doc',

  // 文件输出目录
  output: '/src/api',

  // 缓存目录
  cacheDir: 'node_modules/.pubinfo-openapi',

  // 自定义 hooks, 透传 `@umijs/openapi` 的 `hook` 配置
  hooks: {
    customFunctionName: data => data.operationId
  },

  // 批量配置
  batch: [
    {
      imports: {},
      input: '',
      output: '',
      hooks: {}
    }
  ]
})

Readme

Keywords

Package Sidebar

Install

npm i @pubinfo/openapi

Weekly Downloads

8

Version

0.6.2

License

MIT

Unpacked Size

41 kB

Total Files

15

Last publish

Collaborators

  • werheng
  • wsypower