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

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