1.0.0-alpha.2 • Published 5 years ago

@winupon/swagger-vue v1.0.0-alpha.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

@winupon/swagger-vue

Convert swagger to a vue interface

Install 安装

npm install @winupon/swagger-vue -D

Use 使用

pass swagger url to generater reqested file 传入swagger的地址以生成请求文件

  const swaggerVue = require("@winupon/swagger-vue")
  const url = "" // your swagger url
  swaggerVue(url)

Will generater 将生成的文件

apiFile

This file records the API information retrieved from swagger, and prompts will appear when you use these methods. 这个文件记录了从swagger上获取的api信息,在你使用这些方法的时候会出现相应的提示信息。

import { fetch } from "../../util/request";
import { WINUPON_ACCOUNT, WINUPON_MY } from "../api_type";

export default {
  /**
  * bind account
  *
  * @param { Object } param
  * @param { object } body param.body
  * @param { string } openid param.openid
  */
  [WINUPON_ACCOUNT]({ body, openid }) {
  return fetch(`/winupon/account`, { body, openid }, "POST");
  },

  /**
  * mine
  *
  * @param { Object } param
  * @param { string } openid param.openid
  */
  [WINUPON_MY]({ openid }) {
  return fetch(`/winupon/my`, { openid }, "GET");
  }
}

typeFile

To prevent naming conflicts, pair each in the tpye.js file. 为了防止命名冲突,在tpye.js文件中对每个api进行命名申明。 app/api_type.js

export const WINUPON_ACCOUNT = 'WINUPON_ACCOUNT';
export const WINUPON_MY = 'WINUPON_MY';

indexFile

Export all APIs in the index.js file. 在index.js文件中导出所有的api。

import winupon from "./API/winupon";

export { ...winupon }

Reference 引用Api

In any vue file, you can import api to initiate request. 在任何vue文件中,你都可以使用import引入来发起请求

  import {WINUPON_ACCOUNT, WINUPON_MY} from '../app/index'

  export default {
    async mounted() {
      const res = await WINUPON_ACCOUNT({})
    }
  }