Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f09d1e7416
|
@ -125,6 +125,33 @@ public abstract class ApiImportAbstractParser implements ApiImportParser {
|
|||
return bodyType;
|
||||
}
|
||||
|
||||
protected void addBodyHeader(MsHTTPSamplerProxy request) {
|
||||
String contentType = "";
|
||||
if (request.getBody() != null && StringUtils.isNotBlank(request.getBody().getType())) {
|
||||
switch (request.getBody().getType()) {
|
||||
case Body.WWW_FROM:
|
||||
contentType = "application/x-www-form-urlencoded";
|
||||
break;
|
||||
case Body.JSON:
|
||||
contentType = "application/json";
|
||||
break;
|
||||
case Body.XML:
|
||||
contentType = "application/xml";
|
||||
break;
|
||||
case Body.BINARY:
|
||||
contentType = "application/octet-stream";
|
||||
break;
|
||||
}
|
||||
List<KeyValue> headers = request.getHeaders();
|
||||
if (headers == null) {
|
||||
headers = new ArrayList<>();
|
||||
request.setHeaders(headers);
|
||||
}
|
||||
addContentType(request.getHeaders(), contentType);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected ApiDefinitionResult buildApiDefinition(String id, String name, String path, String method) {
|
||||
ApiDefinitionResult apiDefinition = new ApiDefinitionResult();
|
||||
apiDefinition.setName(name);
|
||||
|
@ -168,8 +195,8 @@ public abstract class ApiImportAbstractParser implements ApiImportParser {
|
|||
return request;
|
||||
}
|
||||
|
||||
protected void addContentType(HttpRequest request, String contentType) {
|
||||
// addHeader(request, "Content-Type", contentType);
|
||||
protected void addContentType(List<KeyValue> headers, String contentType) {
|
||||
addHeader(headers, "Content-Type", contentType);
|
||||
}
|
||||
|
||||
protected void addCookie(List<KeyValue> headers, String key, String value) {
|
||||
|
|
|
@ -74,6 +74,7 @@ public class PostmanParser extends ApiImportAbstractParser {
|
|||
parseBody(request.getBody(), requestDesc);
|
||||
request.setArguments(parseKeyValue(url.getQuery()));
|
||||
request.setHeaders(parseKeyValue(requestDesc.getHeader()));
|
||||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
return apiDefinition;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
MsHTTPSamplerProxy request = buildRequest(operation, pathName, method.name());
|
||||
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name());
|
||||
parseParameters(operation, request);
|
||||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation, operation.getResponses())));
|
||||
buildModule(parentNode, apiDefinition, operation.getTags(), importRequest.isSaved());
|
||||
|
|
|
@ -100,6 +100,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method);
|
||||
parseParameters(operation, request);
|
||||
parseRequestBody(operation.getRequestBody(), request.getBody());
|
||||
addBodyHeader(request);
|
||||
apiDefinition.setRequest(JSON.toJSONString(request));
|
||||
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses())));
|
||||
buildModule(parentNode, apiDefinition, operation.getTags(), importRequest.isSaved());
|
||||
|
|
Loading…
Reference in New Issue