fix(接口自动化): 修复json-schema勾选必填后切回json报错 #1005335
--bug=1005335 --user=赵勇 【github#4790】json-... https://www.tapd.cn/55049933/s/1028239
This commit is contained in:
parent
1175dd747d
commit
af896c9385
|
@ -312,14 +312,8 @@ public class JSONSchemaGenerator {
|
|||
|
||||
private static final SyntaxValidator VALIDATOR = new SyntaxValidator(ValidationConfiguration.byDefault());
|
||||
|
||||
public static String getJson(String jsonSchema) {
|
||||
if (StringUtils.isEmpty(jsonSchema)) {
|
||||
return null;
|
||||
}
|
||||
private static String formerJson(String jsonSchema) {
|
||||
try {
|
||||
JsonNode jsonNode = JsonLoader.fromString(jsonSchema);
|
||||
ProcessingReport report = VALIDATOR.validateSchema(jsonNode);
|
||||
if (report.isSuccess()) {
|
||||
JSONObject root = new JSONObject();
|
||||
generator(jsonSchema, root);
|
||||
// 格式化返回
|
||||
|
@ -328,12 +322,30 @@ public class JSONSchemaGenerator {
|
|||
return gson.toJson(root.get("MS-OBJECT"));
|
||||
}
|
||||
return gson.toJson(root);
|
||||
} catch (Exception e) {
|
||||
return jsonSchema;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getJson(String jsonSchema) {
|
||||
if (StringUtils.isEmpty(jsonSchema)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
JsonNode jsonNode = JsonLoader.fromString(jsonSchema);
|
||||
ProcessingReport report = VALIDATOR.validateSchema(jsonNode);
|
||||
if (report.isSuccess()) {
|
||||
return formerJson(jsonSchema);
|
||||
} else {
|
||||
return report.getExceptionThreshold().toString();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return ex.getMessage();
|
||||
try {
|
||||
return formerJson(jsonSchema);
|
||||
} catch (Exception e) {
|
||||
return jsonSchema;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue