1.6.0 • Published 5 years ago

@yzfe/gen-api v1.6.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

yz-gen-api 根据 swagger 文档,生成 api 代码

根据 swagger API v2 生成接口代码

安装

yarn add @yzfe/gen-api -D
yarn add axios 

使用

npx yz-gen-api build https://petstore.swagger.io/v2/swagger.json -o src/api

命令

npx yz-gen-api build -h
yz-gen-api build <swaggerUrl>

根据 swagger 文档,生成 api 代码

选项:
  --version, -v  显示版本号                                               [布尔]
  --help, -h                                                              [布尔]
  --outPath, -o  生成目录                                                 [必需]

Vue 最佳实现

修改 api 入口文件 index.ts

import * as http from './http'
import client from './client'
import Vue from 'vue'

const api = {
    http,
    defs: client.defs,
    modules: client.modules
}


declare module 'vue/types/vue' {
    interface Vue {
        $api: typeof api
    }
}

export function install(vue: typeof Vue) {
    Object.defineProperty(vue.prototype, '$api', {
        get() {
            return api
        }
    })
}

export default api

Api request / response 值初始化

export default class Login extends Vue {
    protected loginReq: defs.AuthenticationAuthbasicReq = new this.$api.defs.AuthenticationAuthbasicReq()
}
1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago