mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
fix: 修复删除分组后侧边数据没有更新问题
This commit is contained in:
parent
7343c79212
commit
e57817d2bf
@ -2,7 +2,7 @@
|
||||
|
||||
#### Feature
|
||||
|
||||
* 数据导入同步
|
||||
* 数据导入同步,数据导入支持swagger 3.0
|
||||
|
||||
#### Bug Fixed
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
* 修改编辑接口后,再回到测试集合处数据不更新问题
|
||||
* swagger 数据导入支持 2xx 的httpcode
|
||||
* 修复mongodb帐号密码配置错误时引发的错误
|
||||
* 修复删除分组后侧边数据没哟更新问题
|
||||
|
||||
### v1.3.4
|
||||
|
||||
|
@ -59,7 +59,7 @@ class InterfaceList extends Component {
|
||||
// })
|
||||
let r = await this.props.fetchInterfaceList(projectId);
|
||||
this.setState({
|
||||
data: JSON.parse(JSON.stringify(r.payload.data.data))
|
||||
data: r.payload.data.data
|
||||
})
|
||||
|
||||
} else if (isNaN(params.actionId)) {
|
||||
@ -90,6 +90,9 @@ class InterfaceList extends Component {
|
||||
if (this.actionId !== _actionId) {
|
||||
this.actionId = _actionId;
|
||||
this.handleRequest(nextProps)
|
||||
} else if( this.props.catList !== nextProps.catList){
|
||||
this.handleRequest(nextProps)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,6 +193,7 @@ class ProjectData extends Component {
|
||||
reader.readAsText(info.file);
|
||||
reader.onload = async res => {
|
||||
res = importDataModule[this.state.curImportType].run(res.target.result);
|
||||
console.log('res',res);
|
||||
if (this.state.dataSync) {
|
||||
// 开启同步
|
||||
this.showConfirm(res);
|
||||
|
@ -5,7 +5,7 @@ var jsf = require('common/json-schema-mockjs');
|
||||
|
||||
|
||||
function improtData(importDataModule) {
|
||||
var SwaggerData;
|
||||
var SwaggerData, isOAS3;
|
||||
function handlePath(path) {
|
||||
if (path.charAt(0) != "/") {
|
||||
path = "/" + path;
|
||||
@ -15,48 +15,44 @@ function improtData(importDataModule) {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
function openapi2swagger(data) {
|
||||
data = data.replace(/components\/schemas/g, 'definitions');
|
||||
data = data.replace('openapi', 'swagger');
|
||||
data = JSON.parse(data);
|
||||
|
||||
data.definitions = data.components.schemas;
|
||||
delete data.components;
|
||||
|
||||
data.swagger = '2.0';
|
||||
|
||||
_.each(data.paths, (apis) => {
|
||||
_.each(apis, (api) => {
|
||||
_.each(api.responses, (res) => {
|
||||
if(res.content) {
|
||||
if (res.content) {
|
||||
res.schema = res.content['application/json'].schema;
|
||||
delete res.content;
|
||||
}
|
||||
})
|
||||
if(api.requestBody) {
|
||||
if(!api.parameters) api.parameters = [];
|
||||
if (api.requestBody) {
|
||||
if (!api.parameters) api.parameters = [];
|
||||
api.parameters.push({
|
||||
type: 'object',
|
||||
name: 'body',
|
||||
in: 'body',
|
||||
schema: {
|
||||
$ref: api.requestBody.content['application/json'].schema
|
||||
$ref: api.requestBody.content['application/json'].schema.$ref
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function run(res) {
|
||||
try {
|
||||
let interfaceData = { apis: [], cats: [] };
|
||||
if(res.includes('openapi')) {
|
||||
res = openapi2swagger(res);
|
||||
} else {
|
||||
res = JSON.parse(res);
|
||||
res = JSON.parse(res);
|
||||
isOAS3 = res.openapi && res.openapi === '3.0.0'
|
||||
if (isOAS3) {
|
||||
res = openapi2swagger(res)
|
||||
}
|
||||
|
||||
SwaggerData = res;
|
||||
if (res.tags && Array.isArray(res.tags)) {
|
||||
res.tags.forEach(tag => {
|
||||
@ -218,9 +214,11 @@ function improtData(importDataModule) {
|
||||
if (typeof data !== 'object') {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
data.definitions = SwaggerData.definitions;
|
||||
// data.definitions = SwaggerData.definitions;
|
||||
isOAS3 ? data.components = SwaggerData.components : data.definitions = SwaggerData.definitions
|
||||
|
||||
let jsfData = JSON.stringify(jsf(data), null, 2);
|
||||
return jsfData;
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user