Skip to content

Commit

Permalink
change naming and make comment less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
abaskk-msft committed Jun 26, 2024
1 parent 8934bf2 commit e2aeb14
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/YamlValidator/ValidatorResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,24 @@ public ValidatorResults(bool schemaValid, IReadOnlyList<ValidatorError> traversa
TraversalResults = filterErrors(traversalResults);
}

/* *
* Fix: this will filter out the false positives that are not relevant to the error output, when the validation is false
* Filters the errors to only include the errors that are relevant to the schema.
* For all instance paths in the schema with paths oneOf/0 and oneOf/1, we find the max suffix size and only keep the errors
* from that OneOf path with the max suffix size.
* Why? since errors are propogated up the schema validation tree, the errors at the leaf nodes are the
* most relevant but can have false positives due to the OneOf statement in the schema.
* */
// This will filter out the false positives that are not relevant to the error output, when the validation is false
private ReadOnlyCollection<ValidatorError> filterErrors(IReadOnlyList<ValidatorError> traversalResults)
{
var maxSchemaArraySuffixSize = 0;
var maxSchemaObjectSuffixSize = 0;
var arrayTypeFile = "/oneOf/1";
var objectTypeFile = "/oneOf/0";
var arrayTypeSchemaPath = "/oneOf/1";
var objectTypeSchemaPath = "/oneOf/0";
foreach (var err in traversalResults)
{
var errSchemaPath = err.SchemaPath;
if (!errSchemaPath.StartsWith(arrayTypeFile, StringComparison.Ordinal) &&
!err.SchemaPath.StartsWith(objectTypeFile, StringComparison.Ordinal))
if (!errSchemaPath.StartsWith(arrayTypeSchemaPath, StringComparison.Ordinal) &&
!err.SchemaPath.StartsWith(objectTypeSchemaPath, StringComparison.Ordinal))
{
continue;
}

var suffixLength = errSchemaPath.Length - arrayTypeFile.Length;
if (errSchemaPath.StartsWith(arrayTypeFile, StringComparison.Ordinal))
var suffixLength = errSchemaPath.Length - arrayTypeSchemaPath.Length;
if (errSchemaPath.StartsWith(arrayTypeSchemaPath, StringComparison.Ordinal))
{
maxSchemaArraySuffixSize = Math.Max(maxSchemaArraySuffixSize, suffixLength);
}
Expand All @@ -52,14 +45,14 @@ private ReadOnlyCollection<ValidatorError> filterErrors(IReadOnlyList<ValidatorE
foreach (var err in traversalResults)
{
var errSchemaPath = err.SchemaPath;
if (!errSchemaPath.StartsWith(arrayTypeFile, StringComparison.Ordinal) &&
!err.SchemaPath.StartsWith(objectTypeFile, StringComparison.Ordinal))
if (!errSchemaPath.StartsWith(arrayTypeSchemaPath, StringComparison.Ordinal) &&
!err.SchemaPath.StartsWith(objectTypeSchemaPath, StringComparison.Ordinal))
{
filteredErrors.Add(err);
continue;
}

if (errSchemaPath.StartsWith(arrayTypeFile, StringComparison.Ordinal))
if (errSchemaPath.StartsWith(arrayTypeSchemaPath, StringComparison.Ordinal))
{
if (maxSchemaArraySuffixSize >= maxSchemaObjectSuffixSize)
{
Expand Down

0 comments on commit e2aeb14

Please sign in to comment.