# swagger-to-api **Repository Path**: niboac/swagger-to-api ## Basic Information - **Project Name**: swagger-to-api - **Description**: 将swagger文档转为vue的api文件 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-12-15 - **Last Updated**: 2022-07-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # swagger-to-api #### 介绍 将swagger文档转为vue的api文件 参考 https://www.npmjs.com/package/swagger-to-service #### 软件架构 js #### 安装教程 1. npm i 2. npm run test #### 开发说明 1. 在test/index.js 文件中,设置好swagger的yaml文件路径 2. 执行npm run test 3. out文件夹中会产生api文件 #### 在项目中使用 1. 在package.json文件中加入script: gen-api: node ./sts.js 2. 在package.json文件中加入dependencies: "dependencies": { "swagger-to-api": "git+https://niboac@gitee.com/niboac/swagger-to-api.git" } 3. 执行npm run gen-api ``` javascript // sts.js 文件内容 const sts = require('swagger-to-api') sts({ url: 'http://yaml/server/test.yaml', // yaml uri apiPath: './out/api.js', // dist dir of api file utPath: './out/service.ut.js' // dist dir of service ut file, plugins: [{ apply (config) { config.plugin('before-parse', (data, config) => { console.log('processing:', data.info.title) }) } }] }) ``` 效果: ``` javascript /* eslint-disable */ /** * 本文件由工具自动生成,请勿随意改动!!! * @name 管理系统API * @description * @tutorial ./test/backend.yaml */ import api from 'api' import http from 'utils/http' /** * FaqEsInit * @param { Array } params 请求参数 */ export const getFaqFaqesinit = data => { return http.get('/faq/FaqEsInit', data) } /** * 删除CategoryInfo * @param { Array } params 请求参数 */ export const postFaqCategoryinfoDelete = data => { return http.post('/faq/categoryInfo/delete', data) } /** * 修改CategoryInfo * @param { Array } params 请求参数 */ export const postFaqCategoryinfoEdit = data => { return http.post('/faq/categoryInfo/edit', data) } ```