
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
swagger-to-request
Advanced tools
swagger 自动生成 service 相关请求文件
该工具的定位为辅助前端进行接口类型定义
所有的接口类型都会放在 serviceTypes 文件中
// package.json文件
"scripts":{
"swa":"esno ./src/swagger.ts"
}
// swagger.ts
import { generateRequest } from 'swagger-to-request';
generateRequest({
// url:'http://test:8081/test-boot/v2/request.json' json文件也可以
url:'http://test:8081/test-boot/v2/api-docs' // 文档的请求地址
output:'./src/service' // 代码会生成在'./src/service/swagger中'
})
所有的类型会生成在方法前与 serviceTypes.ts 文件中
// 默认使用
import { generateRequest } from 'swagger-to-request';
generateRequest({
url:'http://test:8081/test-boot/v2/api-docs' // 文档的请求地址
output:'./src/service' // 代码会生成在'./src/service/swagger中'
})
默认为 import {request} from '@umijs/max'
generateRequest({
url: "http://test:8081/test-boot/v2/api-docs", // 文档的请求地址
output: "./src/service", // 代码会生成在'./src/service/swagger中'
requestStr: "import axios from 'axios'",
});
generateRequest({
url: "http://test:8081/test-boot/v2/api-docs", // 文档的请求地址
output: "./src/service", // 代码会生成在'./src/service/swagger中'
requestStr: "import axios from 'axios'",
customFunBody: ({
queryStr, //get请求传参
bodyStr, // post请求传参类型
resType, // 数据返回类型
requestUrl, // 请求地址
serviceName, // 请求方法名称
fetchMethod, // 请求类型
}): string => {
return `export const ${serviceName} = (${
queryStr ? "params: " + queryStr : ""
} ${
bodyStr ? "data:" + bodyStr : ""
}) => axios.${fetchMethod}<${resType}>(\`${requestUrl}\`, {${
queryStr ? " params, " : " "
}${bodyStr ? "data" : ""} })\n\n`;
},
});
// 默认生成代码为
import { request } from "@umijs/max";
export const testBootApprovalApprovalByPost = (data: ApprovalDTO) =>
request < R > (`/crm-boot/approval/approval`, { method: "post", data });
// 自定义配置之后生成代码为
import axios from "axios";
export const crmBootRegionListByPost = (data: RegionSearchDTO) =>
axios.post < RListRegionVO > (`/test-boot/region/list`, { data });
FAQs
swagger generate request code
The npm package swagger-to-request receives a total of 20 weekly downloads. As such, swagger-to-request popularity was classified as not popular.
We found that swagger-to-request 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.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.