
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
swagger-to-umi-mock-server
Advanced tools
swagger 文档一健转 umi mock 服务 (swagger docs transform to umi mock server)
Swagger 文档一健转 umi mock 服务 —— by 北森前端团队 beisen.com
# umi项目安装
$ yarn add -D umi umi-plugin-swagger-to-mock
# or
$ npm install -D umi umi-plugin-swagger-to-mock
# 非umi项目安装
$ yarn add -D umi-swagger-server
# or
$ npm install -D umi-swagger-server
# umi项目启动(npm script)
$ PORT=8001 umi dev
# 非umi项目启动(npm script)
$ PORT=8001 umi-swagger-server
# 查看结果
$ curl -X POST http://localhost:8001/mock/store/order
.
├── mock
│ ├── api.js // 普通umi mock文件,可省略
│ └── swagger.js // umi-plugin-swagger-to-mock 动态生成的mock文件
├── node_modules
├── package.json
├── src
│ ├── shared
│ │ └── api
│ │ ├── apiList.js // 动态生成的 api key 列表
│ │ ├── apiMap.js // 动态生成的 api key -> api路径列表
│ │ ├── apiPathToMockPath.js // 用户自定义函数用于转换直实路径到mock路径
│ │ ├── apiRename.js // 用户自定义对象用于api重命名
│ │ ├── index.js // 动态生成,用户在代码中导入,可获得所有api的key到路径的映射
│ │ └── mock.js // 用户自定义mock文件,可以提定哪些api走mock路径
│ └── you-business-code.js
└── swagger
├── json // 分别为需要解析的swagger json文件,会动态遍历此目录
│ ├── swagger.java.json
│ └── swagger.net.json
└── override // 你需要复写的api数据文件,会动态遍历此目录,同步更新mock/swagger.js
├── alipay.js
├── home.js
└── team.js
src/shared/api.js 使用 umi 的 mock 功能
src/shared/apiPathToMockPath.js 用户自定义函数用于转换直实路径到 mock 路径,一般用于代理识别和调试实别,可省略,默认值
module.exports = function(path) {
return `/mock/${path.replace(/^\//, '')}`
}
{
appList: '/queries/third/app/list',
appList: '/queries/client/app/list',
clientCheckstandById: '/queries/client/checkstand/{id}',
...
}
module.exports = {
clientAppList: '/queries/client/app/list',
}
const { uniq } = require('lodash')
module.exports = uniq([
//'appList', 注释掉指定API,将走线上
'clientAppList', // 此API会走Mock服务器
'clientCheckstandById', // 此API会走Mock服务器
])
import api from 'shared/api'
fetch(api.appList, { method: 'POST' }).then(response => {...}) // 请求线上api
fetch(api.clientAppList).then(response => {...}) // 请求mock api
fetch(`${api.clientCheckstandById}${id}`, { method: 'POST' }).then(response => {...}) // 请求mock api
console.log(api)
-------------------
=> {
appList: '/queries/third/app/list',
clientAppList: '/mock/queries/client/app/list',
clientCheckstandById: '/mock/queries/client/checkstand/',
...
}
在项目根目录创建.umirc.js 文件
const path = require('path')
module.exports = {
plugins: [
[
'umi-plugin-swagger-to-mock',
{
swaggerOutputPath: path.join(__dirname, 'src/shared/api'), // 可省略默认为src/shared/api
swaggerPath: path.join(__dirname, 'swagger'), // 可省略,默认为swagger, 此目录须包含两个子目录json 和 override
swaggerDocs: [
// 可省略,默认为swagger/json目录下所有json文件
{
source: 'http://petstore.swagger.io/v2/swagger.json',
dataNode: 'default',
}, // dataNode 为swagger文档存放数据的节点,一般取值: default | 200
{ source: 'swagger.net.json', dataNode: '200' }, // 想要指定swagger/json/ swagger.net.json的dataNode为 200
],
formatData: (data, { source, dataNode, path }) => {
// 可省略,默认转换为{code: 200, message: '成功', data}
return {
code: 200,
message: '成功',
data,
}
},
},
],
],
}
最后请将下列文件添加到.gitignore
src/shared/api/apiList.js
src/shared/api/index.js
mock/swagger.js
将下列文件添加到.eslintignore
src/shared/api/index.js
FAQs
swagger 文档一健转 umi mock 服务 (swagger docs transform to umi mock server)
The npm package swagger-to-umi-mock-server receives a total of 8 weekly downloads. As such, swagger-to-umi-mock-server popularity was classified as not popular.
We found that swagger-to-umi-mock-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.