Skip to content

Commit

Permalink
clean up tests and update public API interface
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Oct 23, 2024
1 parent 9bf3f08 commit ad3b65d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 133 deletions.
12 changes: 0 additions & 12 deletions test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1682,11 +1682,6 @@ namespace Microsoft.OpenApi.Validations.Rules
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiExternalDocs> UrlIsRequired { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiHeaderRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiHeader> HeaderMismatchedDataType { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiInfoRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiInfo> InfoRequiredFields { get; }
Expand All @@ -1697,19 +1692,13 @@ namespace Microsoft.OpenApi.Validations.Rules
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiLicense> LicenseRequiredFields { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiMediaTypeRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiMediaType> MediaTypeMismatchedDataType { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiOAuthFlowRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiOAuthFlow> OAuthFlowRequiredFields { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiParameterRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiParameter> ParameterMismatchedDataType { get; }
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiParameter> ParameterRequiredFields { get; }
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiParameter> PathParameterShouldBeInThePath { get; }
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiParameter> RequiredMustBeTrueWhenInIsPath { get; }
Expand Down Expand Up @@ -1739,7 +1728,6 @@ namespace Microsoft.OpenApi.Validations.Rules
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiSchemaRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiSchema> SchemaMismatchedDataType { get; }
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiSchema> ValidateSchemaDiscriminator { get; }
public static bool TraverseSchemaElements(string discriminatorName, System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiSchema> childSchema) { }
public static bool ValidateChildSchemaAgainstDiscriminator(Microsoft.OpenApi.Models.OpenApiSchema schema, string discriminatorName) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/example",
});
result.Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -107,21 +99,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
// #enum/0 is not an error since the spec allows
// representing an object using a string.
"#/examples/example1/value/y",
"#/examples/example1/value/z",
"#/examples/example2/value"
});
result.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/example",
});
result.Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -106,21 +98,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
// #enum/0 is not an error since the spec allows
// representing an object using a string.
"#/examples/example1/value/y",
"#/examples/example1/value/z",
"#/examples/example2/value"
});
result.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/{parameter1}/example",
});
result.Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -158,21 +150,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
// #enum/0 is not an error since the spec allows
// representing an object using a string.
"#/{parameter1}/examples/example1/value/y",
"#/{parameter1}/examples/example1/value/z",
"#/{parameter1}/examples/example2/value"
});
result.Should().BeTrue();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ public void ValidateDefaultShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/default",
});
result.Should().BeTrue();
}

[Fact]
Expand All @@ -72,15 +64,7 @@ public void ValidateExampleAndDefaultShouldNotHaveDataTypeMismatchForSimpleSchem
var expectedWarnings = warnings.Select(e => e.Message).ToList();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/example",
});
result.Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -122,21 +106,7 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema()
var result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
// #enum/0 is not an error since the spec allows
// representing an object using a string.
"#/enum/1/y",
"#/enum/1/z",
"#/enum/2"
});
result.Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -212,19 +182,7 @@ public void ValidateDefaultShouldNotHaveDataTypeMismatchForComplexSchema()
bool result = !warnings.Any();

// Assert
result.Should().BeFalse();
warnings.Select(e => e.Message).Should().BeEquivalentTo(new[]
{
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage,
RuleHelpers.DataTypeMismatchedErrorMessage
});
warnings.Select(e => e.Pointer).Should().BeEquivalentTo(new[]
{
"#/default/property1/2",
"#/default/property2/0",
"#/default/property2/1/z"
});
result.Should().BeTrue();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -55,8 +55,8 @@ public void RuleSetConstructorsReturnsTheCorrectRules()
Assert.Empty(ruleSet_4.Rules);

// Update the number if you add new default rule(s).
Assert.Equal(23, ruleSet_1.Rules.Count);
Assert.Equal(23, ruleSet_2.Rules.Count);
Assert.Equal(19, ruleSet_1.Rules.Count);
Assert.Equal(19, ruleSet_2.Rules.Count);
Assert.Equal(3, ruleSet_3.Rules.Count);
}

Expand Down

0 comments on commit ad3b65d

Please sign in to comment.