fix(接口测试): swagger2.0导入接口请求参数是否必选没有导入

--bug=1011053 --user=郭雨琦 swagger2.0导入接口请求参数是否必选没有导入
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001011053
This commit is contained in:
guoyuqi 2022-03-16 16:55:40 +08:00 committed by xiaomeinvG
parent 3475581e6a
commit b49f32128e
2 changed files with 23 additions and 2 deletions

View File

@ -293,8 +293,12 @@ public class Swagger2Parser extends SwaggerAbstractParser {
HashSet<String> refSet = new HashSet<>();
Model model = getRefModelType(schema, refSet);
item.setType("object");
if (model != null)
if (model != null){
item.setProperties(parseSchemaProperties(model.getProperties(), refSet));
if(((AbstractModel) model).getRequired()!=null){
item.setRequired(((AbstractModel) model).getRequired());
}
}
} else if (schema instanceof ArrayModel) {
//模型数组
ArrayModel arrayModel = (ArrayModel) schema;
@ -303,8 +307,21 @@ public class Swagger2Parser extends SwaggerAbstractParser {
} else if (schema instanceof ModelImpl) {
ModelImpl model = (ModelImpl) schema;
item.setType("object");
if (model != null)
if (model != null){
item.setProperties(parseSchemaProperties(model.getProperties(), new HashSet<>()));
if(model.getRequired()!=null){
item.setRequired(model.getRequired());
}
}
}else if(schema instanceof AbstractModel){
AbstractModel abstractModel = (AbstractModel) schema;
HashSet<String> refSet = new HashSet<>();
item.setType("object");
if (abstractModel != null)
item.setProperties(parseSchemaProperties(abstractModel.getProperties(), refSet));
if(abstractModel.getRequired()!=null){
item.setRequired(abstractModel.getRequired());
}
}
if (schema.getExample() != null) {
item.getMock().put("mock", schema.getExample());
@ -399,6 +416,9 @@ public class Swagger2Parser extends SwaggerAbstractParser {
Model model = this.definitions.get(simpleRef);
if (model != null) {
item.setProperties(parseSchemaProperties(model.getProperties(), refSet));
if(((AbstractModel) model).getRequired()!=null){
item.setRequired(((AbstractModel) model).getRequired());
}
}
}

View File

@ -21,6 +21,7 @@ public class JsonSchemaItem {
private List<JsonSchemaItem> items;
private Map<String, Object> mock;
private Map<String, JsonSchemaItem> properties;
private List<String> required ;
@JSONField(name = "$schema")
private String schema;