diff --git a/internal/wrappers/results-summary.go b/internal/wrappers/results-summary.go index 9d201b340..29dfc413b 100644 --- a/internal/wrappers/results-summary.go +++ b/internal/wrappers/results-summary.go @@ -36,13 +36,15 @@ type ResultSummary struct { // nolint: govet type APISecResult struct { - APICount int `json:"api_count,omitempty"` - TotalRisksCount int `json:"total_risks_count,omitempty"` - Risks []int `json:"risks,omitempty"` - RiskDistribution []struct { - Origin string `json:"origin,omitempty"` - Total int `json:"total,omitempty"` - } `json:"risk_distribution,omitempty"` + APICount int `json:"api_count,omitempty"` + TotalRisksCount int `json:"total_risks_count,omitempty"` + Risks []int `json:"risks,omitempty"` + RiskDistribution []riskDistribution `json:"risk_distribution,omitempty"` +} + +type riskDistribution struct { + Origin string `json:"origin,omitempty"` + Total int `json:"total,omitempty"` } func (r *ResultSummary) HasEngine(engine string) bool { @@ -59,14 +61,23 @@ func (r *ResultSummary) HasAPISecurity() bool { } func (r *ResultSummary) HasAPISecurityDocumentation() bool { - if len(r.APISecurity.RiskDistribution) > 1 && strings.EqualFold(r.APISecurity.RiskDistribution[1].Origin, "documentation") { - return true + if len(r.APISecurity.RiskDistribution) > 1 { + for _, risk := range r.APISecurity.RiskDistribution { + if strings.EqualFold(risk.Origin, "documentation") { + return true + } + } } return false } func (r *ResultSummary) GetAPISecurityDocumentationTotal() int { - return r.APISecurity.RiskDistribution[1].Total + for _, risk := range r.APISecurity.RiskDistribution { + if strings.EqualFold(risk.Origin, "documentation") { + return risk.Total + } + } + return 0 } func (r *ResultSummary) HasPolicies() bool { @@ -641,9 +652,15 @@ const nonAsyncSummary = `
{{.APISecurity.APICount}}
-
APIs with risk
+
APIs with risk
{{.APISecurity.TotalRisksCount}}
+ {{if .HasAPISecurityDocumentation}} +
+
APIs Documentation
+
{{.GetAPISecurityDocumentationTotal}}
+
+ {{end}} {{end}}`