feat: Postman require

This commit is contained in:
gaoxiaolin.gao 2018-03-16 18:14:32 +08:00
parent 65693f65e7
commit 09c30fe375
3 changed files with 28 additions and 5 deletions

View File

@ -554,6 +554,8 @@ class InterfaceEditForm extends Component {
req_body_other = '' req_body_other = ''
} }
console.log(req_body_other);
const queryTpl = (data, index) => { const queryTpl = (data, index) => {
return ( return (
<Row key={index} className="interface-edit-item-content"> <Row key={index} className="interface-edit-item-content">

View File

@ -1,6 +1,9 @@
import {message} from 'antd' import {message} from 'antd'
import URL from 'url'; import URL from 'url';
const GenerateSchema = require('generate-schema/src/schemas/json.js');
import { json_parse } from '../../common/utils.js'
function postman(importDataModule){ function postman(importDataModule){
@ -136,7 +139,16 @@ function postman(importDataModule){
} }
} }
}else if(item === "path"){ } else if(item === 'req_body_other') {
if(data.headers.indexOf('application/json')>-1){
res[item] = transformJsonToSchema(data[reflect[item]])
} else {
res[item] = data[reflect[item]];
}
}
else if(item === "path"){
res[item] = handlePath.bind(this)(data[reflect[item]]); res[item] = handlePath.bind(this)(data[reflect[item]]);
if(res[item] && res[item].indexOf("/:") > -1){ if(res[item] && res[item].indexOf("/:") > -1){
let params = res[item].substr(res[item].indexOf("/:")+2).split("/:"); let params = res[item].substr(res[item].indexOf("/:")+2).split("/:");
@ -163,13 +175,11 @@ function postman(importDataModule){
} }
else if(item === 'res') { else if(item === 'res') {
let response = handleResponses(data['responses']) let response = handleResponses(data['responses'])
if(response) { if(response) {
res['res_body'] = response['res_body'], res['res_body'] = response['res_body'],
res['res_body_type'] = response['res_body_type'] res['res_body_type'] = response['res_body_type']
} }
} }
else{ else{
res[item] = data[reflect[item]]; res[item] = data[reflect[item]];
@ -182,14 +192,24 @@ function postman(importDataModule){
if(data&&data.length){ if(data&&data.length){
let res = data[0]; let res = data[0];
let response = {}; let response = {};
response['res_body'] = res.text
response['res_body_type'] = res.language === 'json' ? 'json' : 'raw' response['res_body_type'] = res.language === 'json' ? 'json' : 'raw'
response['res_body'] = res.language === 'json' ? transformJsonToSchema(res.text): res.text;
return response; return response;
} }
return null return null
} }
const transformJsonToSchema = (json) => {
let jsonData = json_parse(json)
jsonData = GenerateSchema(jsonData);
let schemaData = JSON.stringify(jsonData)
return schemaData
}
if(!importDataModule || typeof importDataModule !== 'object'){ if(!importDataModule || typeof importDataModule !== 'object'){
console.error('obj参数必需是一个对象'); console.error('obj参数必需是一个对象');

View File

@ -37,6 +37,7 @@
"deref": "^0.7.3", "deref": "^0.7.3",
"easy-json-schema": "0.0.2-beta", "easy-json-schema": "0.0.2-beta",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"generate-schema": "^2.6.0",
"immer": "^1.1.1", "immer": "^1.1.1",
"js-base64": "^2.3.2", "js-base64": "^2.3.2",
"json-schema-faker": "^0.5.0-rc13", "json-schema-faker": "^0.5.0-rc13",