fix(环境管理): 修复导入问Swagger问题

--bug=1007229 --user=赵勇 [github#6835]接口导出后导入,响应内容中的描述信息没有了,同时请求参数中的值没有了 https://www.tapd.cn/55049933/s/1059432
This commit is contained in:
fit2-zhao 2021-10-27 10:56:42 +08:00 committed by fit2-zhao
parent 4f543a5fae
commit 61125cfd84
2 changed files with 17 additions and 14 deletions

View File

@ -220,7 +220,11 @@ public class Swagger3Parser extends SwaggerAbstractParser {
private void parseResponseCode(String response, HttpResponse msResponse) {
if (StringUtils.isNotEmpty(response)) {
msResponse.setStatusCode(JSON.parseObject(response, List.class));
try {
msResponse.setStatusCode(JSON.parseObject(response, List.class));
} catch (Exception e) {
LogUtil.error(e);
}
}
}
@ -761,14 +765,10 @@ public class Swagger3Parser extends SwaggerAbstractParser {
}
statusCodeInfo.put("headers", headers);
// 返回code
JSONArray statusCode = response.getJSONArray("statusCode");
// build 请求体
if (statusCode == null || statusCode.size() < 1 || statusCode.getJSONObject(0).getString("name") == null) {
return response;
}
statusCodeInfo.put("content", buildContent(response));
statusCodeInfo.put("description", "");
// 返回code
JSONArray statusCode = response.getJSONArray("statusCode");
responseBody.put(JSON.toJSONString(statusCode), statusCodeInfo);
return responseBody;
}
@ -799,12 +799,10 @@ public class Swagger3Parser extends SwaggerAbstractParser {
String bodyType = body.getString("type");
if (bodyType == null) {
} else if (bodyType.equals("JSON")) {
} else if (bodyType.equalsIgnoreCase("JSON")) {
try {
if (StringUtils.equals(body.getString("format"), "JSON-SCHEMA")) {
// String jsonSchema = JSONSchemaGenerator.getJson(body.getString("jsonSchema"));
String jsonSchema = body.getString("jsonSchema");
// bodyInfo = buildRequestBodyJsonInfo(JSONObject.parseObject(jsonSchema));
if (StringUtils.isNotBlank(jsonSchema)) {
JSONObject jsonObject = JSONObject.parseObject(jsonSchema);
JSONArray required = new JSONArray();
@ -833,11 +831,15 @@ public class Swagger3Parser extends SwaggerAbstractParser {
((JSONObject) bodyInfo).put("example", body.get("raw").toString());
}
}
} else if (bodyType.equals("XML")) {
} else if (bodyType.equalsIgnoreCase("RAW")) {
bodyInfo = new JSONObject();
((JSONObject) bodyInfo).put("type", "string");
((JSONObject) bodyInfo).put("example", body.get("raw").toString());
} else if (bodyType.equalsIgnoreCase("XML")) {
String xmlText = body.getString("raw");
JSONObject xmlToJson = XMLUtils.XmlToJson(xmlText);
bodyInfo = buildRequestBodyJsonInfo(xmlToJson);
} else if (bodyType.equals("WWW_FORM") || bodyType.equals("Form Data") || bodyType.equals("BINARY")) { // key-value 类格式
} else if (bodyType.equalsIgnoreCase("WWW_FORM") || bodyType.equalsIgnoreCase("Form Data") || bodyType.equalsIgnoreCase("BINARY")) { // key-value 类格式
JSONObject formData = getformDataProperties(body.getJSONArray("kvs"));
bodyInfo = buildformDataSchema(formData);
}

View File

@ -111,8 +111,9 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
headers = new ArrayList<>();
request.setHeaders(headers);
}
addContentType(request.getHeaders(), contentType);
if (StringUtils.isNotEmpty(contentType)) {
addContentType(request.getHeaders(), contentType);
}
}
}