# @yzfe/openapi-generator

> 根据 openapi 规范的文档，生成 typescript 代码

Latest version **1.0.0-alpha.2** (published 2021-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yzfe/openapi-generator
pnpm add @yzfe/openapi-generator
yarn add @yzfe/openapi-generator
bun add @yzfe/openapi-generator
```

Provides the command `yz-oapi-gen`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.2 |
| Published | 2021-12-30 |
| First published | 2020-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Allenice |
| Maintainers | allenice, minfive, allenmo, alanhuang, vfasky, lauginwing, jiaxin, perlou, masonz |

## Links

- npm: https://www.npmjs.com/package/@yzfe/openapi-generator
- npm.io page: https://npm.io/package/@yzfe/openapi-generator

## Dependencies (9)

- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [trash](https://npm.io/package/trash.md) ^6.1.1
- [yargs](https://npm.io/package/yargs.md) ^15.1.0
- [enquirer](https://npm.io/package/enquirer.md) ^2.3.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [nunjucks](https://npm.io/package/nunjucks.md) ^3.2.0
- [prettier](https://npm.io/package/prettier.md) ^1.19.1
- [@yzfe/request](https://npm.io/package/@yzfe/request.md) ^2.0.0-alpha.2
- [openapi-generator](https://npm.io/package/openapi-generator.md) ^0.1.34

## Recent versions

- 1.0.0-alpha.2 (latest) — 2021-12-30
- 1.0.0-alpha.1 — 2021-06-29
- 1.0.0-alpha.0 — 2021-04-17
- 0.1.39 — 2021-02-24
- 0.0.3 — 2020-03-05
- 0.0.2 — 2020-03-05
- 0.0.1 — 2020-03-04

## README

# openapi-generator

根据 openapi 规范的文档，生成 typescript 代码

## 安装

```bash
yarn add @yzfe/openapi-generator --dev
```

## 使用

```
yz-oapi-gen -c ./config-file.js -o ./output-path
```

### api config

api 配置文件是 js 文件，export 配置数组

```js
module.exports = [
    {
        // 模块名称
        name: 'custom-forms',
        // 接口文档地址
        api: 'https://yzt-dev.yzone.co/custom-forms/v2/api-docs',
        // 接口地址前缀
        apiPrefix: '/custom-forms',
        // 生成的 typings 的名字空间
        namespace: 'ApiCustomForms',
        // 自定义生成的接口方法名，对应接口地址的，不包含前缀部分
        customFunctionName: {
            '/form/data/{id}': 'getDataById',
            '/form/data/list': 'getDataList'
        }
    }
]
```

### 使用生成后的代码

默认生成的代码的请求库是使用 [@yzfe/request](https://gitlab.meimeifa.com/fe-group/yzfe-packages/tree/master/packages/request) 的，请先阅读其文档，一般需要配置拦截器才能使用的。

```typescript
import { moduleName } from '生成的目标目录'

moduleName.functionName(datas)
```

实际例子：

```bash
yz-oapi-gen -c ./config-file.js -o ./src/api
```

```ts
import { customForms } from '@/api'

async function() {
    let res = await customForms.form.getDataList({
        memberId: this.memberId,
        page: this.pageInfo.currentPage,
        size: this.pageInfo.pageSize,
        from: this.beginDate,
        to: this.endDate
    })
    console.log(res)
}
```

---
_Source: https://npm.io/package/@yzfe/openapi-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
