# @urland/api-generator

> docs Api接口生成脚步

Latest version **0.0.6** (published 2024-11-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @urland/api-generator
pnpm add @urland/api-generator
yarn add @urland/api-generator
bun add @urland/api-generator
```

Provides the command `sync-api`.

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2024-11-21 |
| First published | 2023-08-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | TBD |
| Maintainers | zhangcc123, tinpont |
| Keywords | api-generator, @urland |

## Links

- npm: https://www.npmjs.com/package/@urland/api-generator
- Repository: a
- npm.io page: https://npm.io/package/@urland/api-generator

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.27.2
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21
- [@types/node](https://npm.io/package/@types/node.md) ^18.7.5

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2024-11-21
- 0.0.4-beta.1 (beta) — 2024-04-10
- 0.0.5-beta.1 — 2024-07-26
- 0.0.5 — 2024-07-24
- 0.0.3-alpha.1 — 2024-02-02
- 0.0.2 — 2024-02-02
- 0.0.2-alpha.3 — 2023-10-25
- 0.0.2-alpha.2 — 2023-10-24
- 0.0.2-alpha.1 — 2023-10-24
- 0.0.1 — 2023-09-25
- 0.0.1-alpha.5 — 2023-08-01
- 0.0.1-alpha.4 — 2023-08-01
- 0.0.1-alpha.3 — 2023-08-01

## README

# 根据 docs Api生成接口及TS类型脚本
##### 稳定版0.0.1版本生成的API，暂不支持一个页面取多端接口前缀
##### 内测版0.0.2-alpha.1 新增dynamicApi属性，支持生成api.get(xxx)一接口多端复用模式。

#### 使用指南
     第一步：`npm i @urland/api-generator -D`
     第二步： 在项目根目录中添加`api-generator-config.ts`配置文件
                ```export default {
                        providers: {
                            'common-api': {
                                url: 'https://xxx/docs/common-api',
                            },
                            'admin-api': {
                                 url: `https://xxx/docs/admin-api`,
                            },
                            'boss-api': {
                                  url: `https://xxx/docs/boss-api`,
                            },
                        },
                    };
                ```   
       第三步：在`package.json`文件`scripts中添加命令`           
                ``` 
                  "scripts": {
                    "sync-api": "sync-api && yarn run lint-fix-api",
                    "lint-fix-api": "eslint --fix --ext .ts src/models src/services",
                  }
                ```
       第四步：执行 npm run sync-api 即可生成代码  
              
###### `lint-fix-api`命令为`eslint`格式生成后的代码，可参考`@urland/eslint-config`包进行配置，也可自行安装eslint。       


#### 属性指南
    providers：配置docsApi地址，如上图common-api作为key。根据key去生成目录及请求api接口类型。如以下：bossApi.get(xxxx)

            export const getUsersCellphoneNumber = async (cellphoneNumber: string, config: AxiosRequestConfig = {}): Promise<UrApiResponse<User>> => {
                const response = await bossApi.get<User>(`/users/cellphone-number/${cellphoneNumber}`, {}, config);
                return response;
            };

    dynamicApi: true   //支持生成api.get(xxx)一接口多端复用模式，除commonApi以外，如api.post(xxxx)。   注：默认不填则按照providers的key为类型

            export const getUsersCellphoneNumber = async (cellphoneNumber: string, config: AxiosRequestConfig = {}): Promise<UrApiResponse<User>> => {
                const response = await api.get<User>(`/users/cellphone-number/${cellphoneNumber}`, {}, config);
                return response;
            };

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