fix: swagger3导入form-data格式请求体参数缺失

--bug=1010045 --user=陈建星 【接口测试】github#10136,swagger导入接口时,导入的参数类型对不上 https://www.tapd.cn/55049933/s/1102604
This commit is contained in:
chenjianxing 2022-02-10 15:16:00 +08:00 committed by zhangdahai112
parent fdf20abe42
commit de277e8efb
1 changed files with 15 additions and 4 deletions

View File

@ -397,9 +397,17 @@ public class Swagger3Parser extends SwaggerAbstractParser {
parseKvBodyItem(schema, body, k, infoMap);
});
} else {
if(data instanceof Schema) {
if(data instanceof Schema) {
Schema dataSchema = (Schema) data;
parseKvBodyItem(schema, body, dataSchema.getName(), infoMap);
if (StringUtils.isNotBlank(dataSchema.getName())) {
parseKvBodyItem(schema, body, dataSchema.getName(), infoMap);
} else if (dataSchema.getProperties() != null) {
dataSchema.getProperties().forEach((k, v) -> {
if (v instanceof Schema) {
parseKvBodyItem(v, body, k.toString(), infoMap);
}
});
}
}
}
}
@ -414,6 +422,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
kv.setType("file");
}
}
if (StringUtils.isNotBlank(schema.getType()) && StringUtils.equals("file", schema.getType())) {
kv.setType("file");
}
if (body != null) {
if (body.getKvs() == null) {
body.setKvs(new ArrayList<>());
@ -804,7 +815,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
return schema;
}
private JSONObject buildformDataSchema(JSONObject kvs) {
private JSONObject buildFormDataSchema(JSONObject kvs) {
JSONObject schema = new JSONObject();
JSONObject properties = new JSONObject();
for (String key : kvs.keySet()) {
@ -942,7 +953,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
bodyInfo = buildRequestBodyJsonInfo(xmlToJson);
} else if (bodyType.equalsIgnoreCase("WWW_FORM") || bodyType.equalsIgnoreCase("Form Data") || bodyType.equalsIgnoreCase("BINARY")) { // key-value 类格式
JSONObject formData = getformDataProperties(body.getJSONArray("kvs"));
bodyInfo = buildformDataSchema(formData);
bodyInfo = buildFormDataSchema(formData);
}
}