fix(sdk): handle empty message and helpUri in SARIF output

Ensure result message.text is never empty (falls back to CheckTitle)
and omit helpUri when RelatedUrl is empty to avoid SARIF validation
warnings.
This commit is contained in:
Andoni A. committed 2026-04-02 16:06:11 +02:00
1 parent 42ab40d079
commit 5bf816ee42
2 files changed
+12 -6

No files matched your search

+12 -5
View File
@@ -41,15 +41,17 @@ class SARIF(Output):
severity = finding.metadata.Severity.lower()
if check_id not in rules:
rules[check_id] = {
rule = {
"id": check_id,
"name": check_id,
"shortDescription": {"text": finding.metadata.CheckTitle},
"fullDescription": {"text": finding.metadata.Description},
"helpUri": finding.metadata.RelatedUrl or "",
"fullDescription": {
"text": finding.metadata.Description or check_id
},
"help": {
"text": finding.metadata.Remediation.Recommendation.Text
or finding.metadata.Description,
or finding.metadata.Description
or check_id,
},
"defaultConfiguration": {
"level": SEVERITY_TO_SARIF_LEVEL.get(severity, "note"),
@@ -65,13 +67,18 @@ class SARIF(Output):
),
},
}
if finding.metadata.RelatedUrl:
rule["helpUri"] = finding.metadata.RelatedUrl
rules[check_id] = rule
rule_index = list(rules.keys()).index(check_id)
result = {
"ruleId": check_id,
"ruleIndex": rule_index,
"level": SEVERITY_TO_SARIF_LEVEL.get(severity, "note"),
"message": {"text": finding.status_extended},
"message": {
"text": finding.status_extended or finding.metadata.CheckTitle
},
}
location = self._build_location(finding)
-1
View File
@@ -221,7 +221,6 @@ class TestSARIF:
assert "id" in rule
assert "shortDescription" in rule
assert "fullDescription" in rule
assert "helpUri" in rule
assert "help" in rule
assert "defaultConfiguration" in rule
assert "properties" in rule