fix(接口测试): 修复swagger导入导出缺少部分数据处理问题

--bug=1020795--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001020795
--bug=1021321--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001021321
--bug=1021412--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001021412
This commit is contained in:
guoyuqi 2022-12-30 16:34:35 +08:00 committed by xiaomeinvG
parent 083fa1c699
commit b1e0378d58
3 changed files with 16 additions and 7 deletions

View File

@ -241,7 +241,7 @@
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.0.24</version>
<version>2.1.8</version>
</dependency>

View File

@ -330,6 +330,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
Set<String> refSet = new HashSet<>();
Map<String, Schema> infoMap = new HashMap();
Schema schema = getSchema(mediaType.getSchema());
if (content.get(contentType) != null && content.get(contentType).getExample() != null && schema.getExample() == null) {
schema.setExample(content.get(contentType).getExample());
}
Object bodyData = null;
if (!StringUtils.equals(contentType, org.springframework.http.MediaType.APPLICATION_JSON_VALUE)) {
bodyData = parseSchemaToJson(schema, refSet, infoMap);
@ -563,7 +566,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
return example == null ? 0 : example;
} else if (value instanceof NumberSchema) {
return example == null ? 0.0 : example;
} else if (value instanceof StringSchema || StringUtils.equals("string", value.getType()) || StringUtils.equals("text", value.getType())) {
} else if (value instanceof StringSchema || StringUtils.equals("string", value.getType()) || StringUtils.equals("text", value.getType()) || value instanceof JsonSchema) {
return example == null ? "" : example;
} else {// todo 其他类型?
return getDefaultStringValue(value.getDescription());
@ -966,7 +969,6 @@ public class Swagger3Parser extends SwaggerAbstractParser {
return new JSONObject();
}
JSONObject responseBody = new JSONObject();
JSONObject statusCodeInfo = new JSONObject();
// build 请求头
JSONObject headers = new JSONObject();
JSONArray headValueList = response.getJSONArray("headers");
@ -982,13 +984,14 @@ public class Swagger3Parser extends SwaggerAbstractParser {
}
}
}
statusCodeInfo.put("headers", headers);
statusCodeInfo.put("content", buildContent(response));
statusCodeInfo.put("description", "");
// 返回code
JSONArray statusCode = response.getJSONArray("statusCode");
for (int i = 0; i < statusCode.size(); i++) {
JSONObject statusCodeInfo = new JSONObject();
statusCodeInfo.put("headers", headers);
statusCodeInfo.put("content", buildContent(response));
statusCodeInfo.put("description", "");
JSONObject jsonObject = statusCode.getJSONObject(i);
jsonObject.get("name");
statusCodeInfo.put("description", jsonObject.get("value"));

View File

@ -5,7 +5,7 @@
<div class="header-bar">
<div>{{ $t('api_test.api_import.data_format') }}</div>
<el-radio-group v-model="selectedPlatformValue">
<el-radio-group v-model="selectedPlatformValue" @input="clearUrParameter">
<span v-for="(item, index) in platforms" :key="index">
<el-radio v-if="!isScenarioModel || item.name != 'Swagger'" :label="item.value">{{ item.name }}</el-radio>
</span>
@ -457,6 +457,12 @@ export default {
this.clearAuthInfo();
}
},
clearUrParameter(value) {
if (value !== 'Swagger2') {
this.clearAuthInfo();
this.authEnable = false;
}
},
buildParam() {
let param = {};
Object.assign(param, this.formData);