Skip to content

Commit b106f0a

Browse files
author
mobiusy
committed
Feat: Support Swagger extension properties
1 parent 59bade3 commit b106f0a

File tree

1 file changed

+12
-0
lines changed
  • exts/yapi-plugin-import-swagger

1 file changed

+12
-0
lines changed

exts/yapi-plugin-import-swagger/run.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ const compareVersions = require('compare-versions');
154154
api.title = data.summary || data.path;
155155
api.desc = data.description;
156156
api.catname = null;
157+
158+
// 处理 swagger 扩展属性
159+
// 如: x-yapi-status 映射为 yapi status字段
160+
const extPrefix = 'x-yapi-';
161+
_.each(api, (value, extfield) => {
162+
if (extfield.startsWith(extPrefix)) {
163+
const yapiField = extfield.replace(extPrefix, '');
164+
api[yapiField] = value;
165+
delete api[yapiField];
166+
}
167+
})
168+
157169
if(data.tags && Array.isArray(data.tags)){
158170
api.tag = data.tags;
159171
for(let i=0; i< data.tags.length; i++){

0 commit comments

Comments
 (0)