fix(接口测试): 修复接口测试导出swagger3文件响应体内容格式错误问题

--bug=1020795 --user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001020795
This commit is contained in:
guoyuqi 2022-12-14 16:43:19 +08:00 committed by 刘瑞斌
parent 0b3cf2a746
commit 07d3deba71
1 changed files with 8 additions and 3 deletions

View File

@ -346,7 +346,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
JsonSchemaItem jsonSchemaItem = parseSchema(schema, refSet);
if (jsonSchemaItem==null){
jsonSchemaItem = new JsonSchemaItem();
if (StringUtils.isNotBlank(schema.getType())) {
if (schema != null && StringUtils.isNotBlank(schema.getType())) {
jsonSchemaItem.setType(schema.getType());
}
}
@ -579,7 +579,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
}
private Schema getSchema(Schema schema) {
if (StringUtils.isBlank(schema.get$ref()) && StringUtils.equalsIgnoreCase(schema.getType(),"string")) {
if (schema != null && StringUtils.isBlank(schema.get$ref()) && StringUtils.equalsIgnoreCase(schema.getType(), "string")) {
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setExample(schema.getExample());
schema = objectSchema;
@ -988,7 +988,12 @@ public class Swagger3Parser extends SwaggerAbstractParser {
statusCodeInfo.put("description", "");
// 返回code
JSONArray statusCode = response.getJSONArray("statusCode");
responseBody.put(JSON.toJSONString(statusCode), statusCodeInfo);
for (int i = 0; i < statusCode.size(); i++) {
JSONObject jsonObject = statusCode.getJSONObject(i);
jsonObject.get("name");
statusCodeInfo.put("description", jsonObject.get("value"));
responseBody.put(jsonObject.get("name").toString(), statusCodeInfo);
}
return responseBody;
}