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,6 +312,21 @@ public class JSONSchemaGenerator {
|
|||
|
||||
private static final SyntaxValidator VALIDATOR = new SyntaxValidator(ValidationConfiguration.byDefault());
|
||||
|
||||
private static String formerJson(String jsonSchema) {
|
||||
try {
|
||||
JSONObject root = new JSONObject();
|
||||
generator(jsonSchema, root);
|
||||
// 格式化返回
|
||||
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
if (root.get("MS-OBJECT") != null) {
|
||||
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;
|
||||
|
@ -320,20 +335,17 @@ public class JSONSchemaGenerator {
|
|||
JsonNode jsonNode = JsonLoader.fromString(jsonSchema);
|
||||
ProcessingReport report = VALIDATOR.validateSchema(jsonNode);
|
||||
if (report.isSuccess()) {
|
||||
JSONObject root = new JSONObject();
|
||||
generator(jsonSchema, root);
|
||||
// 格式化返回
|
||||
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
if (root.get("MS-OBJECT") != null) {
|
||||
return gson.toJson(root.get("MS-OBJECT"));
|
||||
}
|
||||
return gson.toJson(root);
|
||||
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