Skip to content

Commit 5eccf02

Browse files
committed
Merge branch 'sam/validation3' into dm/validation
2 parents bc530c3 + b29d532 commit 5eccf02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+327
-102
lines changed

src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.OpenApi/Properties/SRResource.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="IndentationLevelInvalid" xml:space="preserve">
130130
<value>Indentation level cannot be lower than 0.</value>
131131
</data>
132+
<data name="InputItemShouldBeType" xml:space="preserve">
133+
<value>The input item should be in type of '{0}'.</value>
134+
</data>
132135
<data name="ObjectScopeNeededForPropertyNameWriting" xml:space="preserve">
133136
<value>The active scope must be an object scope for property name '{0}' to be written.</value>
134137
</data>

src/Microsoft.OpenApi/Validations/Rules/OpenApiExternalDocsRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class OpenApiExternalDocsRules
2020
new ValidationRule<OpenApiExternalDocs>(
2121
(context, item) =>
2222
{
23-
// title
23+
// url
2424
context.Push("url");
2525
if (item.Url == null)
2626
{

src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Validations.Rules
1313
public static class OpenApiPathsRules
1414
{
1515
/// <summary>
16-
/// A relative path to an individual endpoint. The field name MUST begin with a slash.
16+
/// A relative path to an individual endpoint. The field name MUST begin with a slash.
1717
/// </summary>
1818
public static ValidationRule<OpenApiPaths> PathNameMustBeginWithSlash =>
1919
new ValidationRule<OpenApiPaths>(

src/Microsoft.OpenApi/Validations/Rules/OpenApiResponseRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class OpenApiResponseRules
2020
new ValidationRule<OpenApiResponse>(
2121
(context, response) =>
2222
{
23-
// title
23+
// description
2424
context.Push("description");
2525
if (String.IsNullOrEmpty(response.Description))
2626
{

src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Validations.Rules
1414
public static class OpenApiServerRules
1515
{
1616
/// <summary>
17-
/// REQUIRED.
17+
/// Validate the field is required.
1818
/// </summary>
1919
public static ValidationRule<OpenApiServer> FieldIsRequired =>
2020
new ValidationRule<OpenApiServer>(

src/Microsoft.OpenApi/Validations/Rules/OpenApiTagRules.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Validations.Rules
1414
public static class OpenApiTagRules
1515
{
1616
/// <summary>
17-
/// REQUIRED.
17+
/// Validate the field is required.
1818
/// </summary>
1919
public static ValidationRule<OpenApiTag> FieldIsRequired =>
2020
new ValidationRule<OpenApiTag>(
@@ -24,7 +24,7 @@ public static class OpenApiTagRules
2424
if (String.IsNullOrEmpty(tag.Name))
2525
{
2626
ValidationError error = new ValidationError(ErrorReason.Required, context.PathString,
27-
String.Format(SRResource.Validation_FieldIsRequired, "name", "Tag"));
27+
String.Format(SRResource.Validation_FieldIsRequired, "name", "tag"));
2828
context.AddError(error);
2929
}
3030
context.Pop();

src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal static class RuleHelpers
1111
/// Input string must be in the format of an email address
1212
/// </summary>
1313
/// <param name="input">The input string.</param>
14-
/// <returns></returns>
14+
/// <returns>True if it's an email address. Otherwise False.</returns>
1515
public static bool IsEmailAddress(this string input)
1616
{
1717
if (String.IsNullOrEmpty(input))

src/Microsoft.OpenApi/Validations/ValidationError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public ValidationError(ErrorReason reason, string path, string message)
5858
/// <returns>The error string.</returns>
5959
public override string ToString()
6060
{
61-
return "ErroCode: " + ErrorCode + ", " + ErrorPath + " | " + ErrorMessage;
61+
return "ErrorCode: " + ErrorCode + ", " + ErrorPath + " | " + ErrorMessage;
6262
}
6363
}
6464
}

src/Microsoft.OpenApi/Validations/ValidationRule.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT license.
33

44
using System;
5-
using System.Diagnostics;
65
using Microsoft.OpenApi.Interfaces;
6+
using Microsoft.OpenApi.Properties;
77

88
namespace Microsoft.OpenApi.Validations
99
{
@@ -49,7 +49,21 @@ internal override Type ElementType
4949

5050
internal override void Evaluate(ValidationContext context, object item)
5151
{
52-
Debug.Assert(item is T, "item should be " + typeof(T));
52+
if (context == null)
53+
{
54+
throw Error.ArgumentNull(nameof(context));
55+
}
56+
57+
if (item == null)
58+
{
59+
return;
60+
}
61+
62+
if (!(item is T))
63+
{
64+
throw Error.Argument(string.Format(SRResource.InputItemShouldBeType, typeof(T).FullName));
65+
}
66+
5367
T typedItem = (T)item;
5468
this._validate(context, typedItem);
5569
}

0 commit comments

Comments
 (0)