Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DataTypeMismatch validation rule from the default ruleset #1888

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions src/Microsoft.OpenApi/Validations/Rules/OpenApiHeaderRules.cs

This file was deleted.

63 changes: 0 additions & 63 deletions src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs

This file was deleted.

39 changes: 0 additions & 39 deletions src/Microsoft.OpenApi/Validations/Rules/OpenApiParameterRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,6 @@ public static class OpenApiParameterRules
context.Exit();
});

/// <summary>
/// Validate the data matches with the given data type.
/// </summary>
public static ValidationRule<OpenApiParameter> ParameterMismatchedDataType =>
new(nameof(ParameterMismatchedDataType),
(context, parameter) =>
{
// example
context.Enter("example");

if (parameter.Example != null)
{
RuleHelpers.ValidateDataTypeMismatch(context, nameof(ParameterMismatchedDataType), parameter.Example, parameter.Schema);
}

context.Exit();

// examples
context.Enter("examples");

if (parameter.Examples != null)
{
foreach (var key in parameter.Examples.Keys)
{
if (parameter.Examples[key] != null)
{
context.Enter(key);
context.Enter("value");
RuleHelpers.ValidateDataTypeMismatch(context,
nameof(ParameterMismatchedDataType), parameter.Examples[key]?.Value, parameter.Schema);
context.Exit();
context.Exit();
}
}
}

context.Exit();
});

/// <summary>
/// Validate that a path parameter should always appear in the path
/// </summary>
Expand Down
43 changes: 0 additions & 43 deletions src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,6 @@ namespace Microsoft.OpenApi.Validations.Rules
[OpenApiRule]
public static class OpenApiSchemaRules
{
/// <summary>
/// Validate the data matches with the given data type.
/// </summary>
public static ValidationRule<OpenApiSchema> SchemaMismatchedDataType =>
new(nameof(SchemaMismatchedDataType),
(context, schema) =>
{
// default
context.Enter("default");

if (schema.Default != null)
{
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), schema.Default, schema);
}

context.Exit();

// example
context.Enter("example");

if (schema.Example != null)
{
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), schema.Example, schema);
}

context.Exit();

// enum
context.Enter("enum");

if (schema.Enum != null)
{
for (var i = 0; i < schema.Enum.Count; i++)
{
context.Enter(i.ToString());
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), schema.Enum[i], schema);
context.Exit();
}
}

context.Exit();
});

/// <summary>
/// Validates Schema Discriminator
/// </summary>
Expand Down
Loading
Loading