generate .ts api files by swagger.json
npm install swagger-codegen-next -gyarn global add swagger-codegen-nextswagger-codegen.config.js
// swagger-codegen.config.jsconstpath=require("path");constcwd=process.cwd();module.exports={// swagger文件地址url: "http://***/swagger.json",// 输出目录output: {path: path.join(cwd,"services"),// default},// 获取接口模块名称getModuleName(url){return/api\/([^\/]*)/.exec(url)[1];},// 获取接口名getMethodName(operationId){returnoperationId;},// 需要跳过生成的接口exclude: [],template: {http: 'import http from "../http";'}};Now you can run the swagger-codegen-next:
swagger-codegen-nextsupport HTTP/HTTPS
{"url": "http://***.swaggger.json"// https://***.swagger.json}
support absolute path
{"url": path.resolve(__dirname,"./swagger.json")}
The output property tells swagger-codegen-next where to emit the api files .
{output: {path: path.join(cwd,'services')// default},}The getModuleName method can help swagger-codegen-next to group the APIs.
{getModuleName(url){return/api\/([^\/]*)/.exec(url)[1]}}add getMethodName to support to customize the name of a method.
skip target swagger paths
eg:
exclude: ["/api/user/add"]
MIT