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

@xubill/free-swagger-userscript

v1.0.1

Published

free-swagger for tampermonkey 修改版

Downloads

4

Readme

推荐使用接入更简单的 浏览器插件版本

free-swagger-userscript

根据 swagger 文档自动生成前端接口代码片段

free-swagger-userscript 基于 free-swagger-core 开发的油猴脚本,增强浏览器端对于 swagger 文档的处理行为

image-20200710125155851

下方的操作栏即 free-swagger-userscript 提供的扩展能力

功能介绍

api 搜索

复制 api 代码片段

复制/递归复制 interface/typedef

复制 api 路径

复制 mock 数据

复制全量 typedef

复制全量 interface

安装 & 使用

free-swagger-userscript 是基于 UserScript 用户脚本拓展插件 (跨平台的浏览器插件)开发的脚本工具. 因此使用前, 我们需要安装浏览器插件 Tampermonkey

安装油猴插件

在 chrome 的拓展工具中心搜索关键字 Tampermonkey

image.png

安装完成后, 浏览器状态栏应该会出现一个图标

img

安装 free-swagger-userscript

安装方式统一为引入 url 安装

脚本地址:https://cdn.jsdelivr.net/npm/free-swagger-userscript/dist/userScript.js

具体操作方式如下

image-20200710132840013

image.png

image.png

image-20200710133402091

使用

进入包含 swagger字段的网页, 你就会发现 Tampermonkey 图标亮了, 有一个小图标表示它在当前网页上注入了一个脚本

image-20200710141155411

这时你会在网页下放发现多了一个操作栏, 祝贺您获得了 swagger-ui 的拓展能力.

image-20200710141538427

匹配更多网址

油猴脚本通过脚本中 @include 字段判断当前网页是否需要注入脚本

添加 @include 字段,使得脚本匹配更多网址

image-20200710141651665

image-20200710141735750

image-20200710141815365

至此,当访问网址包含 swagger / other-url 时,就会注入 free-swagger-exntends 脚本

更新

点击设置,勾选检查更新,输入更新 url https://cdn.jsdelivr.net/npm/free-swagger-userscript/dist/userScript.js 即可收到脚本更新消息

image-20210411155119953

编辑模版

free-swagger-userscript 基于 free-swagger-core,通过模版生成代码片段

默认使用 axios 作为模版,生成的代码片段如下

image-20200710151113242

通过编辑模版,可以自定义生成的代码片段,通过改变入参位置、切换请求库名来适配任意请求库的结构

例如将 axios.request 改成 request,示例如下

image-20210320170732104

image-20210320170350749

模版函数接受多个参数,可以自由组合成想要的代码片段,详细使用方式参考 free-swagger-core

源码调试

npm run serve

复制下面脚本到 tampermonkey

// ==UserScript==
// @author  yeyan1996
// @name  free-swagger-userscript
// @namespace  http://tampermonkey.net/
// @description  free-swagger for tampermonkey
// @version  5.3.4

// @include  /swagger
// @include  /doc.html

// ==/UserScript==


// 创建 DOM 节点
function createDom(type, props, style) {
    const dom = document.createElement(type)
    Object.assign(dom, props)
    Object.assign(dom.style, style)
    return dom
}


// 创建 script 标签
function createScripTag(src) {
    document.body.append(createDom("script", {src}));
}

createScripTag("http://localhost:8888/js/app.js") // 本地调试用

说明

由于网页读取失败,基于上诉内容修改,仅自用。

感谢

感谢原作者yeyan1996