0.0.3-alpha.1 • Published 1 month ago

@urland/api-generator v0.0.3-alpha.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

根据 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;
        };
0.0.4-beta.1

1 month ago

0.0.2

3 months ago

0.0.3-alpha.1

3 months ago

0.0.2-alpha.3

7 months ago

0.0.2-alpha.2

7 months ago

0.0.2-alpha.1

7 months ago

0.0.1

8 months ago

0.0.1-alpha.5

9 months ago

0.0.1-alpha.4

9 months ago

0.0.1-alpha.3

9 months ago

0.0.1-alpha.2

9 months ago

0.0.1-alpha.1

9 months ago