@pubinfo/openapi
v0.7.0
Published
Generate request files according to the OpenAPI.
Downloads
20
Readme
@pubinfo/openapi
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
import { defineConfig } from '@pubinfo/openapi'
export default defineConfig({
// 是否启用,默认 true
enabled: true,
// 忽略缓存强制生成接口文件,默认 false
force: false,
// 预设配置
presets: [
presetName({ /* preset options */ }),
],
// 文件默认导入
imports: {
'@/api': 'request', // import request from '@/api'
'request': ['foo', 'bar'], // import { foo , bar } from 'request'
'./api': [{ name: 'foo', as: 'bar' }] // import { foo as bar } from './api'
},
// 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
},
// 接口文档登录凭证
credentials: {
username: '',
password: ''
},
// 批量配置
batch: [
{
imports: {},
input: '',
output: '',
hooks: {},
presets: [],
}
]
})