fix(接口测试): 解决swagger3导入导出json-schema是否必填值错误问题
--user=郭雨琦 swagger3导出json-schema是否必填值数据结构错误,导入无法保存json-schema是否必填值项
This commit is contained in:
parent
27533deb57
commit
67a636e060
|
@ -458,13 +458,18 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
private JsonSchemaItem parseSchema(Schema schema, Set<String> refSet) {
|
||||
if (schema == null) return null;
|
||||
JsonSchemaItem item = new JsonSchemaItem();
|
||||
if(schema.getRequired()!=null){
|
||||
item.setRequired(schema.getRequired());
|
||||
}
|
||||
if (StringUtils.isNotBlank(schema.get$ref())) {
|
||||
if (refSet.contains(schema.get$ref())) return item;
|
||||
item.setType("object");
|
||||
refSet.add(schema.get$ref());
|
||||
Schema modelByRef = getModelByRef(schema.get$ref());
|
||||
if (modelByRef != null)
|
||||
if (modelByRef != null){
|
||||
item.setProperties(parseSchemaProperties(modelByRef, refSet));
|
||||
item.setRequired(modelByRef.getRequired());
|
||||
}
|
||||
} else if (schema instanceof ArraySchema) {
|
||||
Schema items = ((ArraySchema) schema).getItems();
|
||||
item.setType("array");
|
||||
|
@ -715,6 +720,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
String type = requestBody.getString("type");
|
||||
|
||||
JSONObject parsedParam = new JSONObject();
|
||||
if(required!=null){
|
||||
parsedParam.put("required",required);
|
||||
}
|
||||
if (StringUtils.isNotBlank(type)) {
|
||||
if (StringUtils.equals(type, "array")) {
|
||||
JSONObject items = requestBody.getJSONObject("items");
|
||||
|
@ -727,18 +735,11 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
|||
} else if (StringUtils.equals(type, "object")) {
|
||||
parsedParam.put("type", "object");
|
||||
JSONObject properties = requestBody.getJSONObject("properties");
|
||||
JSONObject swaggerProperties = new JSONObject();
|
||||
properties.keySet().forEach((k) -> {
|
||||
JSONObject item = buildJsonSchema(properties.getJSONObject(k), required);
|
||||
if (required != null && required.contains(k)) {
|
||||
item.put("required", true);
|
||||
}
|
||||
swaggerProperties.put(k, item);
|
||||
});
|
||||
|
||||
if (StringUtils.isNotBlank(requestBody.getString("description"))) {
|
||||
parsedParam.put("description", requestBody.getString("description"));
|
||||
}
|
||||
parsedParam.put("properties", swaggerProperties);
|
||||
parsedParam.put("properties", properties);
|
||||
} else if (StringUtils.equals(type, "integer")) {
|
||||
parsedParam.put("type", "integer");
|
||||
parsedParam.put("format", "int64");
|
||||
|
|
Loading…
Reference in New Issue