fix: postman 导入body格式

This commit is contained in:
chenjianxing 2020-07-17 09:34:39 +08:00
parent b29a4f9109
commit d830cc85db
1 changed files with 14 additions and 1 deletions

View File

@ -14,10 +14,23 @@ import org.apache.commons.lang3.StringUtils;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PostmanParser extends ApiImportAbstractParser {
private static Map<String, String> postmanBodyRowMap;
static {
postmanBodyRowMap = new HashMap<>();
postmanBodyRowMap.put("json", "application/json");
postmanBodyRowMap.put("text", "text/plain");
postmanBodyRowMap.put("html", "text/html");
postmanBodyRowMap.put("xml", "text/xml");
postmanBodyRowMap.put("javascript", "application/x-javascript");
}
@Override
public ApiImport parse(InputStream source) {
String testStr = getApiTestStr(source);
@ -69,7 +82,7 @@ public class PostmanParser extends ApiImportAbstractParser {
if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.RAW.value())) {
body.setRaw(postmanBody.getString(bodyMode));
body.setType(MsRequestBodyType.RAW.value());
String contentType = postmanBody.getJSONObject("options").getJSONObject("raw").getString("language");
String contentType = postmanBodyRowMap.get(postmanBody.getJSONObject("options").getJSONObject("raw").getString("language"));
addContentType(request, contentType);
} else if (StringUtils.equals(bodyMode, PostmanRequestBodyMode.FORM_DATA.value()) || StringUtils.equals(bodyMode, PostmanRequestBodyMode.URLENCODED.value())) {
List<PostmanKeyValue> postmanKeyValues = JSON.parseArray(postmanBody.getString(bodyMode), PostmanKeyValue.class);