fix: har导入

This commit is contained in:
gaoxiaolin.gao 2018-03-19 11:16:10 +08:00
parent 09c30fe375
commit 06154febd3
4 changed files with 32 additions and 11 deletions

View File

@ -554,7 +554,7 @@ class InterfaceEditForm extends Component {
req_body_other = ''
}
console.log(req_body_other);
// console.log("req_body_other",req_body_other);
const queryTpl = (data, index) => {
return (
@ -1148,13 +1148,15 @@ class InterfaceEditForm extends Component {
<span style={{ fontWeight: "500" }}>F9</span>
</div>
) : (
) :
(
<Jeditor onChange={(text)=>{
this.setState({
res_body: text
})
}} data={res_body} />
)}
)
}
<div
id="res_body_json"
style={{

View File

@ -324,6 +324,7 @@ class ProjectData extends Component {
<div className="dataImportTile">
<Select placeholder="请选择导入数据的方式" onChange={this.handleImportType}>
{Object.keys(importDataModule).map((name) => {
return <Option key={name} value={name}>{importDataModule[name].name}</Option>
})}
</Select>

View File

@ -152,4 +152,12 @@ exports.json_parse = function(json){
}catch(err){
return json;
}
}
exports.json_format= function(json){
try{
return JSON.stringify(JSON.parse(json), null, ' ');
}catch(e){
return json;
}
}

View File

@ -1,13 +1,20 @@
import {message} from 'antd'
import URL from 'url';
const GenerateSchema = require('generate-schema/src/schemas/json.js');
import { json_parse } from '../../common/utils.js'
function json_format(json){
try{
return JSON.stringify(JSON.parse(json), null, ' ');
}catch(e){
return json;
}
const transformJsonToSchema = (json) => {
let jsonData = json_parse(json)
jsonData = GenerateSchema(jsonData);
let schemaData = JSON.stringify(jsonData)
return schemaData
}
function postman(importDataModule){
@ -100,6 +107,7 @@ function postman(importDataModule){
interfaceData.apis.push(data);
}
}
console.log(interfaceData)
return interfaceData;
}catch(e){
@ -150,7 +158,9 @@ function postman(importDataModule){
}
}else if(item === 'req_body_other' && reqType === 'json' && data.request.postData){
res[item] = json_format(data.request.postData.text);
res[item] = transformJsonToSchema(data.request.postData.text);
}else if(item === "req_headers"){
res[item] = [{
name: 'Content-Type',
@ -173,7 +183,7 @@ function postman(importDataModule){
}else if(item === 'res_body_type'){
res[item] = 'json';
}else if(item === 'res_body'){
res[item] = json_format(data.response.content.text);
res[item] = transformJsonToSchema(data.response.content.text);
}
else{
res[item] = data.request[reflect[item]];