fix(接口测试): 修复swagger3.0文件导入对content的example没有处理问题

--bug=1021321--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001021321
This commit is contained in:
guoyuqi 2022-12-28 16:31:45 +08:00 committed by xiaomeinvG
parent 48c6b83d1f
commit 65c8ad55ee
1 changed files with 5 additions and 1 deletions

View File

@ -326,9 +326,13 @@ 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).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);
@ -559,7 +563,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(PropertyConstant.STRING, value.getType())) {
} else if (value instanceof StringSchema || StringUtils.equals(PropertyConstant.STRING, value.getType()) || value instanceof JsonSchema) {
return example == null ? StringUtils.EMPTY : example;
} else {// todo 其他类型?
return getDefaultStringValue(value.getDescription());