fix(接口测试): 解决接口导出为swagger时不带模块问题

--user=郭雨琦
--bug=1014699
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014699
This commit is contained in:
guoyuqi 2022-07-08 15:55:46 +08:00 committed by xiaomeinvG
parent 0dd91944aa
commit 82812a58db
3 changed files with 8 additions and 7 deletions

View File

@ -936,9 +936,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
if (body != null) { // 将请求体转换成相应的格式导出 if (body != null) { // 将请求体转换成相应的格式导出
String bodyType = body.getString("type"); String bodyType = body.getString("type");
if (bodyType == null) { if (StringUtils.isNotBlank(bodyType) && bodyType.equalsIgnoreCase("JSON")) {
} else if (bodyType.equalsIgnoreCase("JSON")) {
try { try {
if (StringUtils.equals(body.getString("format"), "JSON-SCHEMA")) { if (StringUtils.equals(body.getString("format"), "JSON-SCHEMA")) {
String jsonSchema = body.getString("jsonSchema"); String jsonSchema = body.getString("jsonSchema");
@ -986,14 +984,17 @@ public class Swagger3Parser extends SwaggerAbstractParser {
} }
} }
String type = respOrReq.getJSONObject("body").getString("type"); String type = null;
if (respOrReq.getJSONObject("body") != null) {
type = respOrReq.getJSONObject("body").getString("type");
}
JSONObject content = new JSONObject(); JSONObject content = new JSONObject();
Object schema = bodyInfo; // 请求体部分 Object schema = bodyInfo; // 请求体部分
JSONObject typeName = new JSONObject(); JSONObject typeName = new JSONObject();
if (schema != null) { if (schema != null) {
typeName.put("schema", schema);//schema.getJSONObject("properties").size() == 0? "" : typeName.put("schema", schema);//schema.getJSONObject("properties").size() == 0? "" :
} }
if (type != null && StringUtils.isNotBlank(type)) { if (StringUtils.isNotBlank(type)) {
content.put(typeMap.get(type), typeName); content.put(typeMap.get(type), typeName);
} }
return content; return content;

View File

@ -1335,7 +1335,7 @@ public class ApiAutomationService {
_importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper); _importCreate(sameList, batchMapper, extApiScenarioMapper, scenarioWithBLOBs, apiTestImportRequest, apiTestCaseMapper, apiDefinitionMapper);
} else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) { } else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) {
if (CollectionUtils.isEmpty(sameList)) { if (CollectionUtils.isEmpty(sameList)) {
if (scenarioWithBLOBs.getVersionId() == null || scenarioWithBLOBs.getVersionId().equals("new")) { if (scenarioWithBLOBs.getVersionId() != null && scenarioWithBLOBs.getVersionId().equals("new")) {
scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion()));
} else { } else {
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId())); scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));

View File

@ -805,7 +805,7 @@ public class ApiDefinitionService {
if (CollectionUtils.isEmpty(collect)) { if (CollectionUtils.isEmpty(collect)) {
String originId = apiDefinition.getId(); String originId = apiDefinition.getId();
//postman 可能含有前置脚本接口定义去掉脚本 //postman 可能含有前置脚本接口定义去掉脚本
if (apiDefinition.getVersionId() == null || apiDefinition.getVersionId().equals("new")) { if (apiDefinition.getVersionId() != null && apiDefinition.getVersionId().equals("new")) {
apiDefinition.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); apiDefinition.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion()));
} else { } else {
apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId()));