Skip to content

Commit

Permalink
Add test case for opting into using the data mismatch validation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Oct 24, 2024
1 parent 2d8640a commit ae0c5a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
};

// Act
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
var defaultRuleSet = ValidationRuleSet.GetDefaultRuleSet();
defaultRuleSet.Add(typeof(OpenApiHeader), OpenApiNonDefaultRules.HeaderMismatchedDataType);
var validator = new OpenApiValidator(defaultRuleSet);

var walker = new OpenApiWalker(validator);
walker.Walk(header);

Expand All @@ -40,7 +43,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeTrue();
result.Should().BeFalse();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
};

// Act
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
var defaultRuleSet = ValidationRuleSet.GetDefaultRuleSet();
defaultRuleSet.Add(typeof(OpenApiParameter), OpenApiNonDefaultRules.ParameterMismatchedDataType);

var validator = new OpenApiValidator(defaultRuleSet);
validator.Enter("{parameter1}");
var walker = new OpenApiWalker(validator);
walker.Walk(parameter);
Expand All @@ -150,7 +153,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeTrue();
result.Should().BeFalse();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ public void ValidateDefaultShouldNotHaveDataTypeMismatchForComplexSchema()
};

// Act
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
var defaultRuleSet = ValidationRuleSet.GetDefaultRuleSet();
defaultRuleSet.Add(typeof(OpenApiSchema), OpenApiNonDefaultRules.SchemaMismatchedDataType);
var validator = new OpenApiValidator(defaultRuleSet);
var walker = new OpenApiWalker(validator);
walker.Walk(schema);

warnings = validator.Warnings;
bool result = !warnings.Any();

// Assert
result.Should().BeTrue();
result.Should().BeFalse();
}

[Fact]
Expand Down

0 comments on commit ae0c5a0

Please sign in to comment.