npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger2axios

v1.0.6

Published

swagger.json 转成 axios 的自动api。包含拦截器及代码注释

Downloads

9

Readme

swagger2axios

引入介绍(Introduction)

可利用swagger.json或swagger的在线api-doc地址 自动生成axios的对应接口代码 包含axios拦截器等 无需下载其他任何模块

安装方式

npm install swagger2axios -D

使用步骤(how to use)


使用步骤

第一、 package.json 配置启动命令
# 例如
"scripts": {
    "getapi": "node node_modules/swagger2axios/src/index.js DOWNLOAD_URL=http://**.**.**.**:****/**/**** OUTPUT=src/utils/autoapi.js"
}
# DOWNLOAD_URL 为 swagger的json  路径  
#       网络地址则如: https://www.swagger.com/swagger.json
#       本地地址则如: src/utils/swagger.json
# OUTPUT       为 autoapi 输出文件路径  如: src/utils/autoapi.js
# 如不加 则默认读取 根目录下名为swagger.json的文件   默认输出目录为项目根目录
第二、 vue 主启动js内添加 请求前缀
# 例如
(1) main.js 下
import * as myHttp from '@/utils/autoapi.js'
(2) main.js 下
# 如本地处理跨域 则:
A:
    myHttp.setDomain('/server')
B:  # config下配置 proxyTable
    proxyTable: {
     '/server/': {
       target: 'http://**.**.**.**:****',
       changeOrigin: true,
       pathRewrite: { '^/server/': '' },
     },
    },
# 如后台接口处理跨域 则
A:     myHttp.setDomain('http://**.**.**.**:****')
(3) main.js 下
# 将 http 请求绑定到vue对象上
Vue.prototype.$http = myHttp
第三、 vue文件使用
# 例如 
this.$http.getVersionUsingGET({
    '***': '***',
    '***': '***'
}).then(function (response) {
    console.log(response.data) //
})

# 【getVersionUsingGET】
可是 生成的autoapi内具体的方法名
也可是swawgger里具体点击具体请求后 url最后面的变量名(如下图 图1)

图1

Image text

1 每次生成会覆盖之前文件代码 如果修改请保存相关修改
2 请确保后台给的swagger.json内容相对完整
3 此代码是参考swagger-vue 项目2次开发的 原项目地址 https://github.com/chenweiqun/swagger-vue 尊重原创 感谢