-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[rest]: improve markdown validation error reporting #3669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature-5.5.12-zns
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -787,81 +787,91 @@ class RestDocumentationGenerator implements DocumentGenerator { | |
| return globalConfigMarkDown | ||
| } | ||
|
|
||
| Boolean isConsistent(GlobalConfigMarkDown md, GlobalConfig globalConfig) { | ||
| if (md == null || globalConfig == null) { | ||
| return false | ||
| } | ||
| List<String> isConsistent(GlobalConfigMarkDown md, GlobalConfig globalConfig) { | ||
| if (md == null) { | ||
| return ["GlobalConfigMarkDown is null"] | ||
| } | ||
| if (globalConfig == null) { | ||
| return ["GlobalConfig is null"] | ||
| } | ||
| String mdPath = | ||
| PathUtil.join(PathUtil.join(Paths.get("../doc").toAbsolutePath().normalize().toString(), | ||
| "globalconfig"), md.globalConfig.category, md.globalConfig.name) + ".md" | ||
| List<String> classes = new ArrayList<>() | ||
| initializer.bindResources.get(globalConfig.getIdentity()).each { classes.add(it.getName()) } | ||
| List<String> newClasses = classes.sort() | ||
| String validatorString = initializer.validatorMap.get(globalConfig.getIdentity()) | ||
| Boolean flag = true | ||
| if (md.globalConfig.name != globalConfig.name) { | ||
| logger.info("name of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| if (md.globalConfig.defaultValue != globalConfig.defaultValue) { | ||
| logger.info("defaultValue of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| if (StringUtils.trimToEmpty(md.globalConfig.description) != StringUtils.trimToEmpty(globalConfig.description)) { | ||
| logger.info("desc of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| if (md.globalConfig.type != globalConfig.type) { | ||
| if (globalConfig.type != null) { | ||
| logger.info("type of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| } | ||
| if (md.globalConfig.category != globalConfig.category) { | ||
| logger.info("category of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| List<String> oldClasses = md.globalConfig.resources.sort() | ||
| if (oldClasses != newClasses) { | ||
| logger.info("classes of ${mdPath} is not latest") | ||
| flag = false | ||
| } | ||
| List<String> mismatches = [] | ||
| if (md.globalConfig.name != globalConfig.name) { | ||
| logger.info("name of ${mdPath} is not latest") | ||
| mismatches.add("name mismatch in ${mdPath}: expected='${md.globalConfig.name}', actual='${globalConfig.name}'") | ||
| } | ||
| if (md.globalConfig.defaultValue != globalConfig.defaultValue) { | ||
| logger.info("defaultValue of ${mdPath} is not latest") | ||
| mismatches.add("defaultValue mismatch in ${mdPath}: expected='${md.globalConfig.defaultValue}', actual='${globalConfig.defaultValue}'") | ||
| } | ||
| if (StringUtils.trimToEmpty(md.globalConfig.description) != StringUtils.trimToEmpty(globalConfig.description)) { | ||
| logger.info("desc of ${mdPath} is not latest") | ||
| mismatches.add("description mismatch in ${mdPath}: expected='${StringUtils.trimToEmpty(md.globalConfig.description)}', actual='${StringUtils.trimToEmpty(globalConfig.description)}'") | ||
| } | ||
| if (md.globalConfig.type != globalConfig.type) { | ||
| if (globalConfig.type != null) { | ||
| logger.info("type of ${mdPath} is not latest") | ||
| mismatches.add("type mismatch in ${mdPath}: expected='${md.globalConfig.type}', actual='${globalConfig.type}'") | ||
| } | ||
| } | ||
| if (md.globalConfig.category != globalConfig.category) { | ||
| logger.info("category of ${mdPath} is not latest") | ||
| mismatches.add("category mismatch in ${mdPath}: expected='${md.globalConfig.category}', actual='${globalConfig.category}'") | ||
| } | ||
| List<String> oldClasses = md.globalConfig.resources.sort() | ||
| if (oldClasses != newClasses) { | ||
| logger.info("classes of ${mdPath} is not latest") | ||
| mismatches.add("resources mismatch in ${mdPath}: expected='${oldClasses}', actual='${newClasses}'") | ||
| } | ||
|
|
||
| if (md.globalConfig.valueRange != (validatorString)) { | ||
| boolean useBooleanValidator = (globalConfig.type == "java.lang.Boolean" | ||
| && md.globalConfig.valueRange == "{true, false}") | ||
| if (validatorString != null || !useBooleanValidator) { | ||
| logger.info("valueRange of ${mdPath} is not latest") | ||
| logger.info("valueRange = ${md.globalConfig.valueRange} validatorString = ${validatorString}") | ||
| flag = false | ||
| } | ||
| } | ||
| return flag | ||
| } | ||
| if (validatorString != null || !useBooleanValidator) { | ||
| logger.info("valueRange of ${mdPath} is not latest") | ||
| logger.info("valueRange = ${md.globalConfig.valueRange} validatorString = ${validatorString}") | ||
| mismatches.add("valueRange mismatch in ${mdPath}: expected='${md.globalConfig.valueRange}', actual='${validatorString}'") | ||
|
Comment on lines
+805
to
+839
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
现在的 mismatch 文案把 Markdown 里的旧值写成 💡 示例- mismatches.add("name mismatch in ${mdPath}: expected='${md.globalConfig.name}', actual='${globalConfig.name}'")
+ mismatches.add("name mismatch in ${mdPath}: markdown='${md.globalConfig.name}', current='${globalConfig.name}'")其余 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| return mismatches | ||
| } | ||
|
|
||
| void checkMD(String mdPath, GlobalConfig globalConfig) { | ||
| String result = ShellUtils.runAndReturn( | ||
| "grep '${PLACEHOLDER}' ${mdPath}").stdout.replaceAll("\n", "") | ||
| if (!result.empty) { | ||
| throw new CloudRuntimeException("Placeholders are detected in ${mdPath}, please replace them by content.") | ||
| } | ||
| GlobalConfigMarkDown markDown = getExistGlobalConfigMarkDown(mdPath) | ||
| if (markDown.desc_CN.isEmpty() | ||
| || markDown.name_CN.isEmpty() | ||
| || markDown.valueRangeRemark.isEmpty() | ||
| || markDown.defaultValueRemark.isEmpty() | ||
| || markDown.resourcesGranularitiesRemark.isEmpty() | ||
| || markDown.additionalRemark.isEmpty() | ||
| || markDown.backgroundInformation.isEmpty() | ||
| || markDown.isUIExposed.isEmpty() | ||
| || markDown.isCLIExposed.isEmpty() | ||
| ) { | ||
| throw new CloudRuntimeException("The necessary information of ${mdPath} is missing, please complete the information before submission.") | ||
| } | ||
| if (!isConsistent(markDown, globalConfig)) { | ||
| throw new CloudRuntimeException("${mdPath} is not match with its definition, please use Repair mode to correct it.") | ||
| } | ||
| } | ||
| if (!result.empty) { | ||
| throw new CloudRuntimeException("Placeholders are detected in ${mdPath}, please replace them by content.") | ||
| } | ||
| GlobalConfigMarkDown markDown = getExistGlobalConfigMarkDown(mdPath) | ||
| List<String> missingFields = [] | ||
| if (markDown.desc_CN.isEmpty()) missingFields.add("desc_CN") | ||
| if (markDown.name_CN.isEmpty()) missingFields.add("name_CN") | ||
| if (markDown.valueRangeRemark.isEmpty()) missingFields.add("valueRangeRemark") | ||
| if (markDown.defaultValueRemark.isEmpty()) missingFields.add("defaultValueRemark") | ||
| if (markDown.resourcesGranularitiesRemark.isEmpty()) missingFields.add("resourcesGranularitiesRemark") | ||
| if (markDown.additionalRemark.isEmpty()) missingFields.add("additionalRemark") | ||
| if (markDown.backgroundInformation.isEmpty()) missingFields.add("backgroundInformation") | ||
| if (markDown.isUIExposed.isEmpty()) missingFields.add("isUIExposed") | ||
| if (markDown.isCLIExposed.isEmpty()) missingFields.add("isCLIExposed") | ||
| List<String> inconsistencies = isConsistent(markDown, globalConfig) | ||
| if (!missingFields.isEmpty() || !inconsistencies.isEmpty()) { | ||
| StringBuilder sb = new StringBuilder("Validation failed for ${mdPath}:\n") | ||
| if (!missingFields.isEmpty()) { | ||
| sb.append("Missing required fields: ${missingFields}\n") | ||
| } | ||
| if (!inconsistencies.isEmpty()) { | ||
| sb.append("Inconsistent fields:\n") | ||
| inconsistencies.each { sb.append("- ${it}\n") } | ||
| } | ||
| throw new CloudRuntimeException(sb.toString()) | ||
| } | ||
| } | ||
|
|
||
| class ElaborationMarkDown { | ||
| private def table = ["|编号|描述|原因|操作建议|更多|"] | ||
|
|
@@ -2815,23 +2825,32 @@ ${additionalRemark} | |
| return System.getProperty("ignoreError") != null | ||
| } | ||
|
|
||
| void testGlobalConfigTemplateAndMarkDown() { | ||
| Map<String, GlobalConfig> allConfigs = initializer.configs | ||
| allConfigs.each { | ||
| String newPath = | ||
| PathUtil.join(PathUtil.join(Paths.get("../doc").toAbsolutePath().normalize().toString(), | ||
| "globalconfig"), it.value.category, it.value.name) + DEPRECATED + ".md" | ||
| if (new File(newPath).exists()) { | ||
| void testGlobalConfigTemplateAndMarkDown() { | ||
| Map<String, GlobalConfig> allConfigs = initializer.configs | ||
| List<String> allErrors = [] | ||
| allConfigs.each { | ||
| String newPath = | ||
| PathUtil.join(PathUtil.join(Paths.get("../doc").toAbsolutePath().normalize().toString(), | ||
| "globalconfig"), it.value.category, it.value.name) + DEPRECATED + ".md" | ||
| if (new File(newPath).exists()) { | ||
| return | ||
| } | ||
| String mdPath = | ||
| PathUtil.join(PathUtil.join(Paths.get("../doc").toAbsolutePath().normalize().toString(), | ||
| "globalconfig"), it.value.category, it.value.name) + ".md" | ||
| File mdFile = new File(mdPath) | ||
| if (!mdFile.exists()) { | ||
| throw new CloudRuntimeException("Not found the document markdown of the global config ${it.value.name} , please generate it first.") | ||
| } | ||
| checkMD(mdPath, it.value) | ||
| } | ||
| } | ||
| } | ||
| String mdPath = | ||
| PathUtil.join(PathUtil.join(Paths.get("../doc").toAbsolutePath().normalize().toString(), | ||
| "globalconfig"), it.value.category, it.value.name) + ".md" | ||
| File mdFile = new File(mdPath) | ||
| if (!mdFile.exists()) { | ||
| allErrors.add("Not found the document markdown of the global config ${it.value.name} , please generate it first.") | ||
| return | ||
|
Comment on lines
+2841
to
+2844
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺失 Markdown 的报错需要带上真实路径。 这里只输出了 💡 建议修改- allErrors.add("Not found the document markdown of the global config ${it.value.name} , please generate it first.")
+ allErrors.add("Global config markdown not found: ${mdPath}. Please generate it first.")As per coding guidelines, "代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写". 🤖 Prompt for AI Agents |
||
| } | ||
| try { | ||
| checkMD(mdPath, it.value) | ||
| } catch (CloudRuntimeException e) { | ||
| allErrors.add(e.message) | ||
| } | ||
| } | ||
| if (!allErrors.isEmpty()) { | ||
| throw new CloudRuntimeException(allErrors.join("\n\n")) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用 Markdown 内容回推报错路径。
这里重新用
md.globalConfig.category/name组装mdPath,但这两个字段本身就是后面要校验的内容。只要 Name 或 Category 过期,最终报错就会指向旧路径,而不是当前实际校验的文件,新的聚合报错会误导排查。💡 建议修改
Also applies to: 862-862
🤖 Prompt for AI Agents