- 在项目目录创建文件 swagger-js-codegen.js
const path = require("path");
var fs = require("fs");
var CodeGen = require("swagger-js-codegen").CodeGen;
var file = "swagger/swagger.json";
var swagger = JSON.parse(fs.readFileSync(file, "UTF-8"));
var reactjsSourceCode = CodeGen.getReactCode({
className: "ClientApi",
swagger: swagger,
beautify: true
});
fs.writeFileSync(path.join(__dirname, "./src/api/swagger-js-codegen.js"), reactjsSourceCode);
- 在package.json文件里创建脚本
"scripts": {
"start": "dotenv -e .env react-scripts start",
"build": "react-scripts build",
"build:uat": "dotenv -e .env.production react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"eslint-fix": "eslint --fix --ext .js --ext .jsx src/",
"swagger-js-codegen": "node swagger-js-codegen.js",
},
- 在命令行执行 npm swagger-js-codegen
评论已关闭