How to copy all interfaces with one click
The first step: Encapsulate the function of the transformation interface (it will be fine if not)
getApiUrl () {
// 接口文件转存http://192.168.0.193:9020/v2/api-docs
window.$get("/v2/api-docs").then((res) => {
// console.log('接口转存文档为' + res.paths)
formatApiUrl(res.paths);
})
}
formatApiUrl (apiSource, apiPrefix) {
apiPrefix = apiPrefix ? apiPrefix : 'user-center';
const paths = apiSource;
const getKey = (str) => {
return str.replace(/\//, '').replace(/\/./g, function (e) {
return e.toUpperCase().replace(/\//g, '')
})
}
const newObj = {
}
for (let i in paths) {
newObj[getKey(i)] = {
name: paths[i]['post'] ? paths[i]['post']['summary']
: paths[i]['get']['summary'],
url: i,
method: paths[i]['post'] ? 'post' : 'get',
center: apiPrefix,
}
paths[i]['post'] && (newObj[getKey(i)].headers = paths[i]
['post']['consumes']);
}
console.log(JSON.stringify(newObj))
console.log(JSON.parse(JSON.stringify(newObj)))
return newObj;
}
Step 2: Put the function into the console let formatApiUrl =(apiSource, apiPrefix) =>{
The above function content
}
Step 3: View the function and display the function type in the console
Note: formatApiUrl (apiSource, apiPrefix) => Indicates that the functions of these two parameters are only for swagger ui
1, apiSource parameter 1: copy the value of the paths object in the data returned by swagger.
2. apiPrefix defaults to user-center and then project-center to execute directly
Step 4: Open the interface document (the swagger ui I use at the moment)
Open the preview of the data returned by the console Network to view the interface api-docs, etc.
Right-click to copy paths, { Copy value Copy property path Copy object } appears and select the first Copy value
Step 5: Go back to the console function formatApiUrl () at this time it appears like this but the type is function
At this time, this function needs to pass in two parameters.
The first parameter is: the copy value above (Copy value)
and the second parameter is: http://192.168.0.41:8000/dqApi/project-center/swagger-ui.html #/
The project-center type in swagger is passed in in string format
Press Enter to display a string in json format for selection Copy
Step 6: Open a new page json.cn, and convert the data copied at the end of Step 5
Call it a day! ! ! Only you can understand! !