| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- const converter = require('oas-raml-converter');
- const fs = require('fs');
- const raml10ToOas20 = new converter.Converter(
- converter.Formats.RAML,
- converter.Formats.OAS20
- );
- const tagsMap = {
- '/auth': 'auth-权限',
- '/commit': 'commit-提交',
- '/course': 'course-课程',
- '/exam': 'exam-考试',
- '/problem': 'problem-题目',
- '/record': 'record-记录',
- '/result': 'result-结果',
- '/user': 'user-用户',
- '/statistic': 'statistic-分析'
- };
- raml10ToOas20
- .convertFile('./index.raml')
- .then(function(json) {
- // 接口名称
- json = json.replace(/operationId/g, 'summary');
- json = JSON.parse(json);
- // tags支持
- tags = Object.values(tagsMap).map(v => ({ name: v, description: v }));
- json['tags'] = tags;
- Object.keys(json.paths).forEach(uri => {
- uriTags = Object.keys(tagsMap)
- .filter(k => uri.startsWith(k))
- .map(k => tagsMap[k]);
- Object.keys(json.paths[uri]).forEach(method => {
- json.paths[uri][method]['tags'] = uriTags;
- });
- });
- fs.writeFileSync('./swagger.json', JSON.stringify(json, null, ' '));
- })
- .catch(function(err) {
- console.error(err);
- });
|