Skip to content

Commit

Permalink
prevented stats from erroring out if there are no inputs
Browse files Browse the repository at this point in the history
also, hard wired the stats to drop off the face of the eath with schema violations.

Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Apr 3, 2024
1 parent 7718f1f commit 58fcbab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions statistics/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
// that reduces churn on building stats over and over for different interfaces.
func CreateReportStatistics(index *index.SpecIndex, info *datamodel.SpecInfo, results *model.RuleResultSet) *reports.ReportStatistics {

// don't go looking for stats if we don't have the necessary data
if index == nil || info == nil || results == nil {
return nil
}

opPCount := index.GetOperationsParameterCount()
cPCount := index.GetComponentParameterCount()

Expand Down Expand Up @@ -51,6 +56,13 @@ func CreateReportStatistics(index *index.SpecIndex, info *datamodel.SpecInfo, re
score = 25.0
}

// if there are any oas-schema rile violations, bottom out the score, an invalid schema is a big deal.
for _, result := range results.Results {
if result.Rule.Id == "oas3-schema" {
score = score - 90
}
}

if score < 0 {
score = 10 // the lowest score we want to present can't be 0, there has to be some hope!
}
Expand Down

0 comments on commit 58fcbab

Please sign in to comment.