diff --git a/pkg/Filter.go b/pkg/Filter.go index 00f31e0..b216a84 100644 --- a/pkg/Filter.go +++ b/pkg/Filter.go @@ -6,30 +6,17 @@ import ( ) func FilterValidationResults(result ValidationResult, conf *Config) ValidationResult { - //var vr []ValidationResult - //for _, result := range validationResults { result.ErrorsForLatest = filterError(result.ErrorsForLatest, conf) result.ErrorsForOriginal = filterError(result.ErrorsForOriginal, conf) - //vr = append(vr, result) - //} return removeIgnoredKeys(result, conf) } func filterError(errors []*openapi3.SchemaError, conf *Config) []*openapi3.SchemaError { var filteredErrors []*openapi3.SchemaError for _, schemaError := range errors { - penultimateValue := len(schemaError.JSONPointer()) - 2 - requestOrLimit := len(schemaError.JSONPointer()) > 2 && (schemaError.JSONPointer()[penultimateValue] == "requests" || schemaError.JSONPointer()[penultimateValue] == "limits") - requestOrLimitIsNumber := false - if requestOrLimit { - switch v := schemaError.Value.(type) { - case string: - requestOrLimitIsNumber = v == "number, integer" - } - } if conf.IgnoreNullErrors || - (strings.TrimSpace(schemaError.Reason) == "Value is not nullable" && schemaError.Schema.Type == "array") || - Contains(schemaError.Schema.Description, []string{"RawExtension*"}) || requestOrLimitIsNumber { + excludeArrayNullError(schemaError) || + excludeRawExtensionError(schemaError) || excludeCPUMemoryNumberError(schemaError) { continue } filteredErrors = append(filteredErrors, schemaError) @@ -80,3 +67,23 @@ func removeIgnoredKeys(result ValidationResult, conf *Config) ValidationResult { } return result } + +func excludeCPUMemoryNumberError(schemaError *openapi3.SchemaError) bool { + penultimateValue := len(schemaError.JSONPointer()) - 2 + requestOrLimit := len(schemaError.JSONPointer()) > 1 && (schemaError.JSONPointer()[penultimateValue] == "requests" || schemaError.JSONPointer()[penultimateValue] == "limits") + if requestOrLimit { + switch v := schemaError.Value.(type) { + case string: + return v == "number, integer" + } + } + return false +} + +func excludeRawExtensionError(schemaError *openapi3.SchemaError) bool { + return Contains(schemaError.Schema.Description, []string{"RawExtension*"}) +} + +func excludeArrayNullError(schemaError *openapi3.SchemaError) bool { + return strings.TrimSpace(schemaError.Reason) == "Value is not nullable" && schemaError.Schema.Type == "array" +}